Mark function arguments of type "T *" as "const T *" where possible
| От | Bertrand Drouvot |
|---|---|
| Тема | Mark function arguments of type "T *" as "const T *" where possible |
| Дата | |
| Msg-id | aThMaTPjSeFq3qTf@ip-10-97-1-34.eu-west-3.compute.internal обсуждение исходный текст |
| Ответы |
Re: Mark function arguments of type "T *" as "const T *" where possible
|
| Список | pgsql-hackers |
Hi hackers, Several functions in the codebase accept "T *" parameters but do not modify the pointed-to data. These have been updated to take "const T *" instead, improving type safety, making the interfaces clearer about their intent and may enable additional optimizations. This change helps the compiler catch accidental modifications and better documents immutability of arguments. This patch is the same idea as 8a27d418f8f but for any type of pointers. Regarding the concern [1] raised during review of 8a27d418f8f about back-patching pain: I believe the benefits of improved type safety and clearer interfaces outweigh the inconvenience of merge conflicts, which are typically straightforward to resolve for signature changes. That said, that's a large patch and I understand the concern. To avoid any risks: - cases that produce -Wdiscarded-qualifiers warnings have been discarded as they would need more investigation. - double pointers are excluded to keep the changes straightforward. - cases that produce new -Wcast-qual warnings have been discarded. As in 8a27d418f8f, no functional behavior is changed. FWIW, the patch has been generated with the help of a coccinelle script [2]. Thoughts? [1]: https://www.postgresql.org/message-id/aNajnjxr7RbpSaMP%40nathan [2]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/misc/mark_const_where_possible.cocci Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Вложения
В списке pgsql-hackers по дате отправления: