All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kővágó Zoltán" <dirty.ice.hu@gmail.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>
Cc: Michael Walle <michael@walle.cc>, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 23/52] audio: remove audio_MIN, audio_MAX
Date: Thu, 27 Dec 2018 13:49:43 +0100	[thread overview]
Message-ID: <c82a6572-bcb7-3577-7332-5420c8cfdbb0@gmail.com> (raw)
In-Reply-To: <3ff67b65-935e-9149-05a7-543752723b06@amsat.org>

On 2018-12-25 11:40, Philippe Mathieu-Daudé wrote:
> On 12/24/18 9:48 PM, Kővágó Zoltán wrote:
>> On 2018-12-24 18:16, Philippe Mathieu-Daudé wrote:
>>> On 12/24/18 3:16 AM, Zoltán Kővágó wrote:
>>>> Hi Phil,
>>>>
>>>> On 2018-12-24 00:49, Philippe Mathieu-Daudé wrote:
>>>>> Hi Zoltán,
>>>>>
>>>>> On 12/23/18 9:51 PM, Kővágó, Zoltán wrote:
>>>>>> There's already a MIN and MAX macro in include/qemu/osdep.h, use them
>>>>>> instead.
>>>>>>
>>>>>> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
>>>>>>
>>>>>> ---
>>>>>>
>>>>>> Changes from v1:
>>>>>> * removed audio_MIN, audio_MAX macros
>>>>>> ---
>>>>> [...]>
>>>>>> diff --git a/audio/audio.h b/audio/audio.h
>>>>>> index ccfef9e10a..bcbe56d639 100644
>>>>>> --- a/audio/audio.h
>>>>>> +++ b/audio/audio.h
>>>>>> @@ -148,23 +148,6 @@ static inline void *advance (void *p, int incr)
>>>>>>      return (d + incr);
>>>>>>  }
>>>>>>  
>>>>>> -#ifdef __GNUC__
>>>>>> -#define audio_MIN(a, b) ( __extension__ ({      \
>>>>>> -    __typeof (a) ta = a;                        \
>>>>>> -    __typeof (b) tb = b;                        \
>>>>>> -    ((ta)>(tb)?(tb):(ta));                      \
>>>>>> -}))
>>>>>> -
>>>>>> -#define audio_MAX(a, b) ( __extension__ ({      \
>>>>>> -    __typeof (a) ta = a;                        \
>>>>>> -    __typeof (b) tb = b;                        \
>>>>>> -    ((ta)<(tb)?(tb):(ta));                      \
>>>>>> -}))
>>>>>> -#else
>>>>>> -#define audio_MIN(a, b) ((a)>(b)?(b):(a))
>>>>>> -#define audio_MAX(a, b) ((a)<(b)?(b):(a))
>>>>>> -#endif
>>>>>> -
>>>>>
>>>>> Those MIN/MAX are smarter than the ones in "qemu/osdep.h", I'd keep them
>>>>> moving them there.
>>>>
>>>> Yes, but only when using gcc (or clang when it emulates gcc).
>>>> Unfortunately, they work differently when one of the expressions has
>>>> side effects, which is a disaster waiting to happen (when some poor folk
>>>> finally tries to compile it with a non-gcc compiler).
>>>
>>> We already use the typeof extension:
>>>
>>> $ git grep typeof|wc -l
>>> 145
>>>
>>> For MIN/MAX I'd use rather use the __auto_type extension.
>>>
>>>> Or do we support any compilers beside gcc and clang? Because if not,
>>>> sure, do it, just remove the #ifdef and keep only the gcc version.
>>>
>>> Yes, this is checked by the ./configure script:
>>>
>>> 1850 # Check whether the compiler matches our minimum requirements:
>>> ...
>>> 1859 #   error You need at least Clang v3.4 to compile QEMU
>>> ...
>>> 1864 #  error You need at least GCC v4.8 to compile QEMU
>>> ...
>>> 1867 # error You either need GCC or Clang to compiler QEMU
>>
>> Fair enough. I've tried to check the documentation for supported
>> compilers, but I haven't found any info. Well, I didn't look at the
>> configure script, I admit that.
> 
> You haven't found any info because the minimum requirements are not well
> documented on the wiki.
> 
>>
>> This is what I came up with:
>>
>> #ifndef MIN
>> #define MIN(a, b) ( __extension__ ({      \
>>     __auto_type _a = (a);                 \
>>     __auto_type _b = (b);                 \
>>     _a > _b ? _b : _a;                    \
>> }))
>> #endif
>> #ifndef MAX
>> #define MAX(a, b) ( __extension__ ({      \
>>     __auto_type _a = (a);                 \
>>     __auto_type _b = (b);                 \
>>     _a < _b ? _b : _a;                    \
>> }))
>> #endif
>>
>>
>> I changed it a bit, since a and b are the macro parameters, so they are
>> the variables that we should put into parentheses, and I renamed ta/tb
>> to _a/_b, this way they're less likely to clobber some other variables.
> 
> Sounds good. Now the parentheses around a/b are not necessary.
> 
> I wonder however if it wouldn't be cleaner to previously add:
> 
> #ifdef MIN
> # undef MIN
> #endif
> 
> and for MAX, rather than only use these macros if undefs.

Um, this broke a few things. It also means until now in some cases it
used some random definition of MIN/MAX instead of the one in the header.

/home/dirty_ice/qemu/include/qemu/osdep.h:240:5: error: ‘__auto_type’
used with a bit-field initializer
/home/dirty_ice/qemu/include/qemu/osdep.h:247:35: error: braced-group
within expression allowed only inside a function

The first one is fixable with an explicit cast (ugly but works), but the
second one is more problematic. It means we can't write stuff like

USBPort  uports[MAX(MAXPORTS_2, MAXPORTS_3)];

when not in a function. So we either need a dumb version of MIN/MAX, or
scrape the idea altogether.

> 
>> To be honest, we could probably drop the __extension__ keyword too,
>> we're not compiling with -pedantic. Other than audio_MIN and audio_MAX,
>> it only appears in the DO_UPCAST macro.
> 
> Fine with me!
> 
> If you have this patch ready, you can send it alone out of this series,
> no need to resend this whole series for this patch.

There will be adjustmets to other patches too, so I think I'll just
consolidate them.

Regards,
Zoltan

  reply	other threads:[~2018-12-27 12:49 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-23 20:51 [Qemu-devel] [PATCH v2 00/52] Audio 5.1 patches Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 01/52] qapi: support alternates in OptsVisitor Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 02/52] qapi: support nested structs " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 03/52] qapi: qapi for audio backends Kővágó, Zoltán
2019-01-10  2:49   ` Eric Blake
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 04/52] audio: use qapi AudioFormat instead of audfmt_e Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 05/52] audio: -audiodev command line option: documentation Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 06/52] audio: -audiodev command line option basic implementation Kővágó, Zoltán
2019-01-07 13:13   ` Markus Armbruster
2019-01-07 20:48     ` Zoltán Kővágó
2019-01-08  3:42       ` Markus Armbruster
2019-01-10  0:13         ` Zoltán Kővágó
2019-01-10  7:25           ` Gerd Hoffmann
2019-01-10  9:40             ` Zoltán Kővágó
2019-01-10 10:37               ` Gerd Hoffmann
2019-01-08  6:06       ` Gerd Hoffmann
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 07/52] alsaaudio: port to -audiodev config Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 08/52] coreaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 09/52] dsoundaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 10/52] noaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 11/52] ossaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 12/52] paaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 13/52] sdlaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 14/52] spiceaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 15/52] wavaudio: " Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 16/52] audio: -audiodev command line option: cleanup Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 17/52] audio: reduce glob_audio_state usage Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 18/52] audio: basic support for multi backend audio Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 19/52] audio: add audiodev properties to frontends Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 20/52] audio: audiodev= parameters no longer optional when -audiodev present Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 21/52] paaudio: do not move stream when sink/source name is specified Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 22/52] paaudio: properly disconnect streams in fini_* Kővágó, Zoltán
2018-12-23 20:51 ` [Qemu-devel] [PATCH v2 23/52] audio: remove audio_MIN, audio_MAX Kővágó, Zoltán
2018-12-23 23:49   ` Philippe Mathieu-Daudé
2018-12-24  2:16     ` Zoltán Kővágó
2018-12-24 17:16       ` Philippe Mathieu-Daudé
2018-12-24 20:48         ` Kővágó Zoltán
2018-12-25 10:40           ` Philippe Mathieu-Daudé
2018-12-27 12:49             ` Kővágó Zoltán [this message]
2019-01-07  9:54               ` Gerd Hoffmann
2019-01-07 14:26                 ` Eric Blake
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 24/52] audio: do not run each backend in audio_run Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 25/52] paaudio: fix playback glitches Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 26/52] audio: remove read and write pcm_ops Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 27/52] audio: use size_t where makes sense Kővágó, Zoltán
2018-12-24  6:19   ` Pavel Dovgalyuk
2018-12-25 11:08   ` Philippe Mathieu-Daudé
2019-01-07  9:58     ` Gerd Hoffmann
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 28/52] audio: api for mixeng code free backends Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 29/52] alsaaudio: port to the new audio backend api Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 30/52] coreaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 31/52] dsoundaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 32/52] noaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 33/52] ossaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 34/52] paaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 35/52] sdlaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 36/52] spiceaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 37/52] wavaudio: " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 38/52] audio: remove remains of the old " Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 39/52] audio: unify input and output mixeng buffer management Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 40/52] audio: remove hw->samples, buffer_size_in/out pcm_ops Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 41/52] audio: common rate control code for timer based outputs Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 42/52] audio: split ctl_* functions into enable_* and volume_* Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 43/52] audio: add mixeng option (documentation) Kővágó, Zoltán
2019-01-10  1:43   ` Eric Blake
2019-01-10  9:12     ` Markus Armbruster
2019-01-16 20:27     ` Zoltán Kővágó
2019-01-16 22:40       ` Eric Blake
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 44/52] audio: make mixeng optional Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 46/52] audio: support more than two channels in volume setting Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 47/52] audio: replace shift in audio_pcm_info with bytes_per_frame Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 48/52] audio: basic support for multichannel audio Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 49/52] paaudio: channel-map option Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 50/52] usb-audio: do not count on avail bytes actually available Kővágó, Zoltán
2018-12-23 20:52 ` [Qemu-devel] [PATCH v2 52/52] usbaudio: change playback counters to 64 bit Kővágó, Zoltán
2018-12-25 10:50   ` Philippe Mathieu-Daudé
2018-12-27 22:08     ` Kővágó Zoltán
2018-12-25 10:43 ` [Qemu-devel] [PATCH v2 00/52] Audio 5.1 patches Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c82a6572-bcb7-3577-7332-5420c8cfdbb0@gmail.com \
    --to=dirty.ice.hu@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=kraxel@redhat.com \
    --cc=michael@walle.cc \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.