Re: get_progname() should not be const char *? - Mailing list pgsql-hackers

From Robert Haas
Subject Re: get_progname() should not be const char *?
Date
Msg-id CA+Tgmob=heimU9JOuN81Spib5TygayWjAP32-hZiLA0rS6m3jQ@mail.gmail.com
Whole thread Raw
In response to Re: get_progname() should not be const char *?  (Phil Sorber <phil@omniti.com>)
Responses Re: get_progname() should not be const char *?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Feb 5, 2013 at 12:18 AM, Phil Sorber <phil@omniti.com> wrote:
> On Mon, Feb 4, 2013 at 10:52 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Phil Sorber <phil@omniti.com> writes:
>>> get_progname() returns a strdup()'d value. Shouldn't it then be simply
>>> char * and not const char *? Otherwise free() complains loudly without
>>> a cast.
>>
>> 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.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: sql_drop Event Trigger
Next
From: Dimitri Fontaine
Date:
Subject: Re: sql_drop Event Trigger