I asked this on apache-modules, but got no reply - it was probably the
wrong place to ask anyway.
I'm trying to unerstand the code behind rings, and I am puzzled by how the
sentinel is computed. Why is the offset to the next pointer in the _base_
subtracted from the pointer to _head_, and what's the point of the offset
subtraction.
In other words, instead of
#define APR_RING_SENTINEL(hp, elem, link) \
(struct elem *)((char *)(hp) - APR_OFFSETOF(struct elem, link))
Why not:
#define APR_RING_SENTINEL(hp, elem) \
(struct elem *)(hp)
It so happens that the APR_RING_ENTRY is always first in the element
structure, and so the offset is 0 which is why it works (and the macros
above yeld same result). But it seems to me that if the APR_RING_ENTRY
was't first, then the result of APR_RING_SENTINEL could be a pointer to
somewhere before beginning of head, or some place within head but before
APR_RING_HEAD, which could be some arbitrary and not necessarily constant
value.
The documentation for APR_RING_ENTRY first says that a structure can have
multiple APR_RING_ENTRY's for different rings, but then it warns that
APR_RING_ENTRY should always be first which seems to me
self-contradictory.
I also looked at the ring.h in splim code, and there it does the same
offset subtraction thing which makes no sense to me.
What am I missing?
Thanks,
Grisha