dsound: Avoid implicit cast of interface pointer. [RFC]

Sebastian Lackner sebastian at fds-team.de
Tue Mar 15 23:46:33 CDT 2016

Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>

To catch errors like http://source.winehq.org/patches/data/120308 easier in the future,
I would like to propose, that we replace CONTAINING_RECORD and similar macros with a
typesafe definition (on compilers where this is possible). The linux kernel source
contains an example how to do that, but there are multiple solutions available:

#define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
        (type *)( (char *)__mptr - offsetof(type,member) );})

One disadvantage is that we'll have to add explicit casts to a couple of places, like below.
Other dlls which would require explicit casts at a couple of places:

amstream, d2d1, d3d11, d3d8, d3d9, ddraw, dwrite, msxml3, oleaut32, quartz, rpcrt4, vbscript

I would say its still worth the effort, what do you guys think? Please accept this patch
ONLY if there is a general agreement to do this for all DLLs, it doesn't make any sense to
do this only for parts of the wine source.

 dlls/dsound/primary.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c
index 3f8a478..6f280f8 100644
--- a/dlls/dsound/primary.c
+++ b/dlls/dsound/primary.c
@@ -626,7 +626,7 @@ out:
 static inline IDirectSoundBufferImpl *impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface)
     /* IDirectSoundBuffer and IDirectSoundBuffer8 use the same iface. */
-    return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSoundBuffer8_iface);
+    return CONTAINING_RECORD((IDirectSoundBuffer8 *)iface, IDirectSoundBufferImpl, IDirectSoundBuffer8_iface);
 /* This sets this format for the primary buffer only */

More information about the wine-patches mailing list