add sys/containerof.h and implement __containerof
The sys/queue.h did use container_of() which was bad idea because of container_of is hidden from userland and therefore we block use cases in a way (even as user can define its own container_of. As an secondary reason, there is at least DRM driver boldly creating its own container_of without any checks if it is already defined or not. To reduce the issues and still provide useful macro, lets rename container_of to __containerof and move it to its own private header.
As a followup, we can fix the use cases for container_of and finally remove it from sys/stddef.h.
Updated by Joshua M. Clulow over 1 year ago
A survey has demonstrated that it's used in a handful of places in the gate already. The construct is sufficiently nuanced that it makes sense to have just one copy of it (as we wish to do with, say,
offsetof()). By centralising on one implementation it's easier to add compile time type safety features (as this new header already seeks to do).
Updated by Toomas Soome over 1 year ago
Gordon Ross wrote:
What problem is solved by having illumos headers provide (any sort of) container_of() macro?
Seems like it might be going to a lot of trouble for something not standard and not all that widely used.
I do suggest to use src.illumos.org. It is rather useful tool to find answers to such questions.
Updated by Electric Monk about 1 year ago
- Status changed from In Progress to Closed
- % Done changed from 90 to 100
commit 94c3dad2979525d0a82595f3d8350a6116aba8ed Author: Toomas Soome <firstname.lastname@example.org> Date: 2018-11-12T04:37:51.000Z 9851 add sys/containerof.h and implement __containerof Reviewed by: Joshua M. Clulow <email@example.com> Reviewed by: Andy Fiddaman <firstname.lastname@example.org> Approved by: Joshua M. Clulow <email@example.com>