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

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: get_progname() should not be const char *?
Дата
Msg-id CA+Tgmob=heimU9JOuN81Spib5TygayWjAP32-hZiLA0rS6m3jQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: get_progname() should not be const char *?  (Phil Sorber <phil@omniti.com>)
Ответы Re: get_progname() should not be const char *?
Список 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 по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: sql_drop Event Trigger
Следующее
От: Dimitri Fontaine
Дата:
Сообщение: Re: sql_drop Event Trigger