[vlc-devel] [PATCH 1/2] posix/wait: do not use alignof on expression

Marvin Scholz epirat07 at gmail.com
Fri Aug 7 15:37:47 CEST 2020



On 7 Aug 2020, at 14:42, Rémi Denis-Courmont wrote:

> Hi,
>
> You can use _Generic() if you want to match types. No need for 
> compiler-dependent ifdef'ery.
>
> Might be overkill here though.

I thought about that too but the following does not work:

# define VLC_ALIGNOF(t, expr) \
   (_Generic(expr, t: _Alignof(t)))

atomic_uint *addr;
VLC_ALIGNOFT(atomic_uint, *addr);

This fails to compile with:
error: '_Generic' selector of type 'unsigned int' is not compatible with 
any association

>
> Le 7 août 2020 07:55:35 GMT+03:00, Steve Lhomme <robux4 at ycbcr.xyz> a 
> écrit :
>> OK for both. Although it would be nice to have a safety check in case
>> the underlying type changes and the alignof is not valid anymore.
>>
>> May a static_assert when compiling with GCC, like
>> #if defined(__GNUC__) && !defined(__llvm__) &&
>> !defined(__INTEL_COMPILER)
>> static_assert(alignof(*addr) == alignof(atomic_uint), "type 
>> mismatch");
>> #endif
>>
>>
>> On 2020-08-07 6:44, Marvin Scholz wrote:
>>> Using alignof not on a type but an expression is a GNU extension and
>>> causes the following warning:
>>>
>>>     warning: '_Alignof' applied to an expression is a GNU extension
>>> ---
>>>   src/posix/wait.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/posix/wait.c b/src/posix/wait.c
>>> index 584cc493b1a..3fa6890193a 100644
>>> --- a/src/posix/wait.c
>>> +++ b/src/posix/wait.c
>>> @@ -52,7 +52,7 @@ static struct wait_bucket
>>>   static struct wait_bucket *wait_bucket_get(atomic_uint *addr)
>>>   {
>>>       uintptr_t u = (uintptr_t)addr;
>>> -    size_t idx = (u / alignof (*addr)) % ARRAY_SIZE(wait_buckets);
>>> +    size_t idx = (u / alignof (atomic_uint)) %
>> ARRAY_SIZE(wait_buckets);
>>>
>>>       return &wait_buckets[idx];
>>>   }
>>> -- 
>>> 2.24.3 (Apple Git-128)
>>>
>>> _______________________________________________
>>> vlc-devel mailing list
>>> To unsubscribe or modify your subscription options:
>>> https://mailman.videolan.org/listinfo/vlc-devel
>>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>
> -- 
> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez 
> excuser ma brièveté.


> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list