const qualifier for list APIs

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: const qualifier for list APIs
Date: 2022-11-16 10:34:54
Message-ID: CAExHW5sGRMU_Vypqr9tQaDwmFmkSj+Km6X8NxzA7HBa7JbZ=ig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,
Functions like lappend_*() in list.c do not modify the second
argument. So it can be qualified as const. Any reason why we don't do
that? Is it because the target pointer ptr_value is not const
qualified?

In my code, I am using lappend() and passing it the output of
pq_getmsgstring() which returns const char *. The list is used to just
collect these pointers to be scanned later a few times within the same
function. So there is no possibility of freeing or changing area
within the StringInfo. So the coding practice though questionable, is
safe and avoids unnecessary pallocs. But SonarQube does complain about
it.

--
Best Wishes,
Ashutosh Bapat

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo NAGATA 2022-11-16 10:53:02 Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Previous Message Bharath Rupireddy 2022-11-16 10:31:55 Re: Report checkpoint progress with pg_stat_progress_checkpoint (was: Report checkpoint progress in server logs)