Re: get_progname() should not be const char *?

From: Phil Sorber <phil(at)omniti(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: get_progname() should not be const char *?
Date: 2013-02-06 16:33:56
Message-ID: CADAkt-itUg7DW9AcFEjXi6dxYT7BX8CXKzPapoOa4BoXrhH11A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Feb 6, 2013 at 11:22 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Tue, Feb 5, 2013 at 12:18 AM, Phil Sorber <phil(at)omniti(dot)com> wrote:
>>> On Mon, Feb 4, 2013 at 10:52 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>>> I don't believe that callers should be trying to free() the result.
>>>> Whether it's been strdup'd or not is not any of their business.
>
>>> Is that just because of the nature of this specific function?
>
>> I can't presume to speak for Tom, but I think so. Sometimes the API
>> of a function includes the notion that the caller should pfree the
>> result. Sometimes it doesn't. The advantage of NOT including that in
>> the API contract is that you can sometimes do optimizations that would
>> be impossible otherwise - e.g. you can return the same palloc'd string
>> on successive calls to the function; or you can sometimes return a
>> statically allocated string.
>
> Yeah. In this particular case, it seems rather obvious that the
> function should be returning the same string each time --- if it's
> actually doing a fresh malloc, that sounds like a bug.

It does, but it's noted in a comment that it's only expected to be run once.

>
> But in any case, adding or removing a const qualifier from a function's
> result typically goes along with an API-contract change as to whether
> the caller is supposed to free the result or not. My objection here
> was specifically that I don't believe the contract for get_progname
> includes caller-free now, and I don't want it to start being that.

That's fair. Thanks for the explanation.

>
> regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2013-02-06 16:36:14 Re: [PATCH] pg_isready (was: [WIP] pg_ping utility)
Previous Message Dimitri Fontaine 2013-02-06 16:33:43 Re: sql_drop Event Trigger