Feature #9851
closedadd sys/containerof.h and implement __containerof
100%
Description
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.
Related issues
Updated by Joshua M. Clulow almost 4 years ago
- Related to Bug #9731: uts: update sys/queue.h added
Updated by Joshua M. Clulow almost 4 years ago
As part of testing this change, I think we'll want to make sure we can build the DRM gate: https://github.com/illumos/gfx-drm
Updated by Gordon Ross almost 4 years ago
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.
Updated by Joshua M. Clulow almost 4 years 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 almost 4 years 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 Joshua M. Clulow over 3 years ago
Note that while integrating this I built it and inspected the wsdiff
output. The noisiest changes were in the t4nex
driver, but by far and away most of the changes were just related to line numbers in calls to assfail()
.
Updated by Electric Monk over 3 years ago
- Status changed from In Progress to Closed
- % Done changed from 90 to 100
git commit 94c3dad2979525d0a82595f3d8350a6116aba8ed
commit 94c3dad2979525d0a82595f3d8350a6116aba8ed Author: Toomas Soome <tsoome@me.com> Date: 2018-11-12T04:37:51.000Z 9851 add sys/containerof.h and implement __containerof Reviewed by: Joshua M. Clulow <josh@sysmgr.org> Reviewed by: Andy Fiddaman <omnios@citrus-it.net> Approved by: Joshua M. Clulow <josh@sysmgr.org>