Обсуждение: Cleaning up array_ref() and array_set()

Поиск
Список
Период
Сортировка

Cleaning up array_ref() and array_set()

От
David Geier
Дата:
Hi hackers,

We have array_ref() and array_set() which are merely wrappers around
array_get_element() and array_set_element(). The wrappers take an
ArrayType * argument while array_{get|set}_element() take a Datum as
argument; like most of the other array functions.

array_ref() and array_set() are relicts from the following commit from 2015:


commit e983c4d1aa42d613542cf222e222b034918374b1
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Mon Feb 16 12:23:58 2015 -0500

...
However, there's a fair amount of code using array_ref and array_set
with arrays that *are* known to be ArrayType structures, and there might
be more such places in third-party code.


This has changed over the years. On master there are only 5 calls to
array_ref() and 5 calls to array_set() left. Are there any objections
against cleaning up the code by removing array_ref() and array_set()?

--
David Geier



Re: Cleaning up array_ref() and array_set()

От
Álvaro Herrera
Дата:
On 2026-Feb-24, David Geier wrote:

> This has changed over the years. On master there are only 5 calls to
> array_ref() and 5 calls to array_set() left. Are there any objections
> against cleaning up the code by removing array_ref() and array_set()?

I think it would be kinda silly to oppose the removal of use of an
essentially deprecated API for no reason; however, those functions are
used by the GUC machinery directly as exported functions (because the
functions operate on arrays as ArrayType), so if you wanted to change
that, you'd incur in an API break.  So that case is different: would you
want to impose a change on third-party authors that are using these
functions?

For me the answer would be, if we gain something, and the change is easy
for them to make, then sure, let's change it.  If we don't gain
anything, then ... why break things for them?

First example I found on codesearch.debian.net is:
https://sources.debian.org/src/credcheck/4.6-1/credcheck.c?hl=2811#L2811

Maybe it's not a big deal, but that's an assessment that I think should
be made.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"No es bueno caminar con un hombre muerto"



Re: Cleaning up array_ref() and array_set()

От
Tom Lane
Дата:
=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@kurilemu.de> writes:
> On 2026-Feb-24, David Geier wrote:
>> This has changed over the years. On master there are only 5 calls to
>> array_ref() and 5 calls to array_set() left. Are there any objections
>> against cleaning up the code by removing array_ref() and array_set()?

> For me the answer would be, if we gain something, and the change is easy
> for them to make, then sure, let's change it.  If we don't gain
> anything, then ... why break things for them?

Yeah, I'm pretty much -1 on this proposal.  Those functions are
trivial wrappers, for sure, but by the same token removing them
saves almost nothing.  Also, it would cost code and legibility
at the call sites, which would have to add PointerGetDatum() and
DatumGetArrayTypeP() steps.  So on balance this hardly seems like
a win even without considering its side-effects on extensions.

            regards, tom lane