pgsql: Improve pg_list.h's linitial(), lsecond() and co macros

Поиск
Список
Период
Сортировка
От David Rowley
Тема pgsql: Improve pg_list.h's linitial(), lsecond() and co macros
Дата
Msg-id E1kMiGf-0007I4-8s@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Improve pg_list.h's linitial(), lsecond() and co macros

Prior to this commit, the linitial(), lsecond(), lthird(), lfourth()
macros and their int and Oid list cousins would call their corresponding
inlined function to fetch the cell of interest.  Those inline functions
were kind enough to return NULL if the particular cell did not exist.
Unfortunately, the care that these functions took was of no relevance to
the calling macros as they proceeded to directly dereference the returned
value without any regard to whether that value was NULL or not.  If it had
been, we'd have segfaulted.

Of course, the fact that we would have segfaulted on misuse of these
macros just goes to prove that nobody is relying on the empty or list too
small checks.  So here we just get rid of those checks completely.

The existing inline functions have been left alone as someone may be using
those directly.  We just replace the call within each macro to use
list_nth_cell().

For the llast*() case we require a new list_last_cell() inline function to
get away from the multiple evaluation hazard that we'd get if we fetched
->length on the macro's parameter.

Author: David Rowley
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAApHDvpo1zj9KhEpU2cCRZfSM3Q6XGdhzuAS2v79PH7WJBkYVA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cc99baa43e0ed83ac18fcbde31f2ab7274eb26cf

Modified Files
--------------
src/include/nodes/pg_list.h | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)


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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Improve range checks of options for pg_test_fsync and pg_test_ti
Следующее
От: Fujii Masao
Дата:
Сообщение: pgsql: Improve tab-completion for DEALLOCATE.