Re: libpq: Remove redundant null pointer checks before free()

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: libpq: Remove redundant null pointer checks before free()
Дата
Msg-id 20220619095533.7u35bbei3a2sswdm@alvherre.pgsql
обсуждение исходный текст
Ответ на Re: libpq: Remove redundant null pointer checks before free()  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
Ответы Re: libpq: Remove redundant null pointer checks before free()  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On 2022-Jun-17, Peter Eisentraut wrote:

> From 355ef1a68be690d9bb8ee0524226abd648733ce0 Mon Sep 17 00:00:00 2001
> From: Peter Eisentraut <peter@eisentraut.org>
> Date: Fri, 17 Jun 2022 12:09:32 +0200
> Subject: [PATCH v2 3/3] Remove redundant null pointer checks before PQclear
>  and PQconninfofree
> 
> These functions already had the free()-like behavior of handling NULL
> pointers as a no-op.  But it wasn't documented, so add it explicitly
> to the documentation, too.

For PQclear() specifically, one thing that I thought a few days ago
would be useful would to have it return (PGresult *) NULL.  Then the
very common pattern of doing "PQclear(res); res = NULL;" could be
simplified to "res = PQclear(res);", which is nicely compact and is
learned instantly.

I've not seen this convention used anywhere else though, and I'm not
sure I'd advocate it for other functions where we use similar patterns
such as pfree/pg_free, so perhaps it'd become too much of a special
case.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: 15beta1 tab completion of extension versions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: libpq: Remove redundant null pointer checks before free()