| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Mark function arguments of type "T *" as "const T *" where possible |
| Date: | 2025-12-10 17:44:26 |
| Message-ID: | aTmxeo3SdNkaUE7W@ip-10-97-1-34.eu-west-3.compute.internal |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Wed, Dec 10, 2025 at 06:39:40AM +0000, Bertrand Drouvot wrote:
> Hi,
>
> On Tue, Dec 09, 2025 at 04:20:57PM +0000, Bertrand Drouvot wrote:
> > To avoid any risks:
> >
> > - cases that produce -Wdiscarded-qualifiers warnings have been discarded as
> > they would need more investigation.
> >
> > - double pointers are excluded to keep the changes straightforward.
> >
> > - cases that produce new -Wcast-qual warnings have been discarded.
>
> Despite the above precautions, I just realized there are still "unwanted" const
> additions (more on that later).
What I disliked in v1 is that it added const to produce things like:
"
static void
SetAt(const metastring *s, int pos, char c)
{
if ((pos < 0) || (pos >= s->length))
return;
*(s->str + pos) = c;
}
"
While this is technically correct so the compiler does not complain (because
s->str is a non const pointer and the added const does not apply to
what s->str points to), adding const here defeats the purpose and is misleading.
The functions clearly modify data accessible through the parameter.
In v2, I removed all the ones that are similar to those. I checked and
the only ones are those introduced by v1.
That's still a large patch though (while focusing only on static functions).
Out of curiosity, I looked at the largest patches (based on the number of files changed)
since the last 10 years. If we remove the "Update copyright", Translation updates
and pgindent ones, that gives:
425 dbbca2cf299 Remove unused #include's from backend .c files
346 3c49c6facb2 Convert documentation to DocBook XML
343 578b229718e Remove WITH OIDS support, change oid catalog column visibility.
337 c29c578908d Don't use SGML empty tags
333 1b105f9472b Use palloc_object() and palloc_array() in backend code
278 c5385929593 Make all Perl warnings fatal
265 e6927270cd1 meson: Add initial version of meson based build system
234 1ff01b3902c Convert SGML IDs to lower case
216 2eb4a831e5f Change TRUE/FALSE to true/false
212 611806cd726 Add trailing commas to enum definitions
It means it would be the 8th largest with 251 files touched in v2. Note that
1b105f9472b is from today.
Thoughts?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Mark-function-arguments-of-type-T-as-const-T-wher.patch | text/x-diff | 397.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Matthias van de Meent | 2025-12-10 17:46:03 | SQL-level pg_datum_image_equal |
| Previous Message | Robert Haas | 2025-12-10 17:43:48 | Re: Bypassing cursors in postgres_fdw to enable parallel plans |