[vlc-devel] [PATCH] objects: get the vlc_object_t from vlc_object_internals using vlc_internals()

Steve Lhomme robux4 at gmail.com
Tue Jul 25 20:58:44 CEST 2017


Le 25 juil. 2017 19:45, "Rémi Denis-Courmont" <remi at remlab.net> a écrit :

Le tiistaina 25. heinäkuuta 2017, 19.22.19 EEST Steve Lhomme a écrit :
> On Tue, Jul 25, 2017 at 6:33 PM, Rémi Denis-Courmont <remi at remlab.net>
wrote:
> > Le tiistaina 25. heinäkuuta 2017, 18.06.32 EEST Steve Lhomme a écrit :
> >> So that's it coherent with the rest of the usages.
> >
> > Not really. The other uses operate on an initialized object. Here, we
are
> > creating and initializing the object.
>
> It's just about accessing the pointer.

Says who? I wrote those accessor macros, and that´s not how I conceived them
nor how I think of them. Using accessors on unitialized objects makes no
sense
to me.


Insisting on having distinct ways to access the same thing is what doesn't
make sense to me. But if you do insist then add a static assert to ensure
when you compile that your advanced pointer tricks actually match in both
cases.

> It doesn't matter what is in the pointed data.

The current implementation of the macros is such that initialization does
not
matter. Likewise, it is such that this patch does not matter; it replaces
one
expression with an equivalent expression.

So nack.

> > flexible array in ISO C ensures that the two expressions are equivalent.
> > One uses byte offsets, and the other direct pointer arithmetic.
>
> If that was equivalent, this wouldn't fail:
> static_assert( sizeof(struct vlc_object_internals) !=
>              offsetof(struct vlc_object_internals, aligned_end),
>              "invalid align_end access");

It *is* equivalent, and that assertion *cannot* fail.

By definition of pointer arithmetic, pointer plus one equals the pointer
plus
the size of pointed type and by definition of flexible arrays, the offset
of a
flexible array within its contained structure is the size of the structure.


Can you point to doc about that because I couldn't understand how it works
in the regular case (and it does). Because my understanding of container_of
is that it gives the starting offset of the field in the structure. Except
in this case it's the end of the structure.

That was the whole point of appending aligned_end in the first place.

--
雷米‧德尼-库尔蒙
https://www.remlab.net/

_______________________________________________
vlc-devel mailing list
To unsubscribe or modify your subscription options:
https://mailman.videolan.org/listinfo/vlc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170725/a1650e66/attachment.html>


More information about the vlc-devel mailing list