[vlc-devel] [vlc-commits] demux: make p_sys void * (refs #18504, #17078)

Rémi Denis-Courmont remi at remlab.net
Mon Dec 4 16:46:00 CET 2017


Le maanantaina 4. joulukuuta 2017, 16.23.56 EET Steve Lhomme a écrit :
> On Mon, Dec 4, 2017 at 4:21 PM, Jean-Baptiste Kempf <jb at videolan.org> wrote:
> > Hello,
> > 
> > On Mon, 4 Dec 2017, at 16:12, Steve Lhomme wrote:
> >> I did read both issues before sending my first comment. I think using
> >> void* is the wrong solution to both problems. And that's what I said.
> > 
> > What do you suggest to solve the ODR issue ?
> 
> This patch(es) don't solve the ODR issue.

And nobody ever claimed that they did, as far as I am aware.

> The issue it solves is merging the structures into one.

It does not that issue either. It solves one issue:
- Allow using a non-structure type as opaque data.

It helps with two outstanding issues:
1) Merging stream_t and demux_t.
2) Program-level typedefs ODR.

> You could use :
> 
> union {
>   demux_sys_t *p_sys_demux;
>   access_sys_t *p_sys_access;
>  ...
> };
> 
> And keep the strong typing.

First, that would require renaming the opaque data member in *all* modules, 
even those that already systematically used an intermediate variable.

And then, it would not make any progress on the ODR issue, as we would still 
be limited to one typename per capability.

It should be obvious but there is no and never was an issue with translation 
unit ODR. The C++ compiler enforces ODR at that level, so it is very hard to 
get wrong. The ODR issue is only program-level: all definitions of a single 
type must be essentially identical (the exact requirements are more subtle, 
but that´s the practical result).

There are only two base types that are adequate for opaque data in C: void 
pointers and character pointers. No other pointer type can portably represent 
any pointer type. Character pointers are worse in every respect to void 
pointers, requiring a lot more casting.

Then structure type pointers can represent any other structure type pointer. 
But that will require just as much casting as character pointers, if/when 
structure type names must be distinct.

It is obviously not an accident that the ISO and POSIX C libraries use void 
pointers for opaque data. Likewise other large modular open-source C projects, 
e.g. Linux kernel, libav/FFmpeg. This is the best (least bad) type.

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



More information about the vlc-devel mailing list