diff mbox

[1/4] blockdev.h: Add GCC attribute (check format arguments)

Message ID 1277982502-4196-2-git-send-email-weil@mail.berlios.de
State Rejected
Headers show

Commit Message

Stefan Weil July 1, 2010, 11:08 a.m. UTC
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 blockdev.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Blue Swirl July 1, 2010, 8:10 p.m. UTC | #1
On Thu, Jul 1, 2010 at 11:08 AM, Stefan Weil <weil@mail.berlios.de> wrote:
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  blockdev.h |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/blockdev.h b/blockdev.h
> index 23ea576..3c5c85d 100644
> --- a/blockdev.h
> +++ b/blockdev.h
> @@ -42,7 +42,8 @@ extern int drive_get_max_bus(BlockInterfaceType type);
>  extern void drive_uninit(DriveInfo *dinfo);
>  extern const char *drive_get_serial(BlockDriverState *bdrv);
>
> -extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
> +extern QemuOpts *drive_add(const char *file, const char *fmt, ...)
> +    __attribute__ ((__format__ (__printf__, 2, 3)));
>  extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi,
>                              int *fatal_error);

I lost the cover letter, so this applies to all patches: Wouldn't it
make sense to make GCC_FMT_ATTR(n, m) from audio/audio_int.h available
universally and then use that?
Stefan Weil July 1, 2010, 9:20 p.m. UTC | #2
Am 01.07.2010 22:10, schrieb Blue Swirl:
> On Thu, Jul 1, 2010 at 11:08 AM, Stefan Weil <weil@mail.berlios.de> wrote:
>> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
>> ---
>>  blockdev.h |    3 ++-
>>  1 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/blockdev.h b/blockdev.h
>> index 23ea576..3c5c85d 100644
>> --- a/blockdev.h
>> +++ b/blockdev.h
>> @@ -42,7 +42,8 @@ extern int drive_get_max_bus(BlockInterfaceType type);
>>  extern void drive_uninit(DriveInfo *dinfo);
>>  extern const char *drive_get_serial(BlockDriverState *bdrv);
>>
>> -extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
>> +extern QemuOpts *drive_add(const char *file, const char *fmt, ...)
>> +    __attribute__ ((__format__ (__printf__, 2, 3)));
>>  extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi,
>>                              int *fatal_error);
>
> I lost the cover letter, so this applies to all patches: Wouldn't it
> make sense to make GCC_FMT_ATTR(n, m) from audio/audio_int.h available
> universally and then use that?


That's a matter of personal taste:

GCC_FMT_ATTR(n, m) is shorter, but a human reader has to
look it up once to see what it does (ok, some readers might
guess it right). The compiler has to look it up, too, so
a common header file is needed.

When I prepared the patches, I did not notice that some
functions used GCC_FMT_ATTR. I added the __attribute__
macro to these functions and got a compiler error...
This shows that at least for me GCC_FMT_ATTR was confusing
(of course it no longer is).

Some people prefer GCC_FMT_ATTR because they want to
be able to redefine it for non-gcc compilers.

__attribute__ can also be redefined for that case, so that
is not a very strong argument.

I prefer using __attribute__ without intermediate macro,
but don't mind if a different style is preferred for qemu.

Regards
Stefan
malc July 1, 2010, 10:02 p.m. UTC | #3
On Thu, 1 Jul 2010, Stefan Weil wrote:

> Am 01.07.2010 22:10, schrieb Blue Swirl:
> > On Thu, Jul 1, 2010 at 11:08 AM, Stefan Weil <weil@mail.berlios.de> wrote:
> > > Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> > > ---
> > >  blockdev.h |    3 ++-
> > >  1 files changed, 2 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/blockdev.h b/blockdev.h
> > > index 23ea576..3c5c85d 100644
> > > --- a/blockdev.h
> > > +++ b/blockdev.h
> > > @@ -42,7 +42,8 @@ extern int drive_get_max_bus(BlockInterfaceType type);
> > >  extern void drive_uninit(DriveInfo *dinfo);
> > >  extern const char *drive_get_serial(BlockDriverState *bdrv);
> > > 
> > > -extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
> > > +extern QemuOpts *drive_add(const char *file, const char *fmt, ...)
> > > +    __attribute__ ((__format__ (__printf__, 2, 3)));
> > >  extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi,
> > >                              int *fatal_error);
> > 
> > I lost the cover letter, so this applies to all patches: Wouldn't it
> > make sense to make GCC_FMT_ATTR(n, m) from audio/audio_int.h available
> > universally and then use that?
> 
> 
> That's a matter of personal taste:
> 
> GCC_FMT_ATTR(n, m) is shorter, but a human reader has to
> look it up once to see what it does (ok, some readers might
> guess it right). The compiler has to look it up, too, so
> a common header file is needed.
> 
> When I prepared the patches, I did not notice that some
> functions used GCC_FMT_ATTR. I added the __attribute__
> macro to these functions and got a compiler error...
> This shows that at least for me GCC_FMT_ATTR was confusing
> (of course it no longer is).
> 
> Some people prefer GCC_FMT_ATTR because they want to
> be able to redefine it for non-gcc compilers.
> 
> __attribute__ can also be redefined for that case, so that
> is not a very strong argument.

Just to be pedantic, you can _not_ redfined __attribute the
name is reserved..

> 
> I prefer using __attribute__ without intermediate macro,
> but don't mind if a different style is preferred for qemu.
> 
> Regards
> Stefan
> 
>
diff mbox

Patch

diff --git a/blockdev.h b/blockdev.h
index 23ea576..3c5c85d 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -42,7 +42,8 @@  extern int drive_get_max_bus(BlockInterfaceType type);
 extern void drive_uninit(DriveInfo *dinfo);
 extern const char *drive_get_serial(BlockDriverState *bdrv);
 
-extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
+extern QemuOpts *drive_add(const char *file, const char *fmt, ...)
+    __attribute__ ((__format__ (__printf__, 2, 3)));
 extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi,
                              int *fatal_error);