Re: [PATCH] yavta: Format type errors for non x86 arches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Sakari

On Wed, 20 Sept 2023 at 14:40, Sakari Ailus <sakari.ailus@xxxxxx> wrote:
>
> Hi Ricardo,
>
> On Wed, Sep 20, 2023 at 02:19:54PM +0200, Ricardo Ribalda wrote:
> > Hi Laurent, Hi Sakari
> >
> >
> >
> > On Tue, 19 Sept 2023 at 23:02, Laurent Pinchart
> > <laurent.pinchart@xxxxxxxxxxxxxxxx> wrote:
> > >
> > > On Tue, Sep 19, 2023 at 08:22:57PM +0000, Sakari Ailus wrote:
> > > > Hi Ricardo,
> > > >
> > > > On Tue, Sep 19, 2023 at 10:10:41PM +0200, Ricardo Ribalda wrote:
> > > > > Hi Sakari
> > > > >
> > > > > On Tue, 19 Sept 2023 at 22:07, Sakari Ailus <sakari.ailus@xxxxxx> wrote:
> > > > > >
> > > > > > Hi Ricardo,
> > > > > >
> > > > > > Thanks for the patch.
> > > > > >
> > > > > > On Tue, Sep 19, 2023 at 04:01:23PM +0200, Ricardo Ribalda wrote:
> > > > > > > mipsel64el, ppc64el, ia64, ppc64, sparc64 and x32 have different lenghts
> > > > > > > for long long ints, which result in some compilation errors.
> > > > > > >
> > > > > > > Lets add some castings to help the compiler deal with this.
> > > > > > >
> > > > > > > We cannot use the Format macro constants ffrom inttypes because they
> > > > > > > seem to not be compatible with kernel (__u64 et al) types.
> > > > > > >
> > > > > > > Signed-off-by: Ricardo Ribalda <ricardo@xxxxxxxxxxx>
> > > > > > > ---
> > > > > > >  yavta.c | 35 +++++++++++++++++++++--------------
> > > > > > >  1 file changed, 21 insertions(+), 14 deletions(-)
> > > > > > >
> > > > > > > diff --git a/yavta.c b/yavta.c
> > > > > > > index d562863..bf54e4f 100644
> > > > > > > --- a/yavta.c
> > > > > > > +++ b/yavta.c
> > > > > > > @@ -1313,7 +1313,8 @@ static void video_query_menu(struct device *dev,
> > > > > > >                       printf("  %u: %.32s%s\n", menu.index, menu.name,
> > > > > > >                              menu.index == value ? " (*)" : "");
> > > > > > >               else
> > > > > > > -                     printf("  %u: %lld%s\n", menu.index, menu.value,
> > > > > > > +                     printf("  %u: %lld%s\n", menu.index,
> > > > > >
> > > > > > Could you instead use PRId64 for this? You can avoid casting to another
> > > > > > type this way. Same for the other cases.
> > > > >
> > > > > Already tried this:
> > > > >
> > > > > @@ -1313,7 +1313,7 @@ static void video_query_menu(struct device *dev,
> > > > >                         printf("  %u: %.32s%s\n", menu.index, menu.name,
> > > > >                                menu.index == value ? " (*)" : "");
> > > > >                 else
> > > > > -                       printf("  %u: %lld%s\n", menu.index, menu.value,
> > > > > +                       printf("  %u: %" PRId64 "%s\n", menu.index, menu.value,
> > > > >                                menu.index == value ? " (*)" : "");
> > > > >         };
> > > > >  }
> > > > >
> > > > > but gcc was not happy:
> > > > >
> > > > > yavta.c: In function ‘video_query_menu’:
> > > > > yavta.c:1316:11: warning: format ‘%ld’ expects argument of type ‘long
> > > > > int’, but argument 3 has type ‘__s64’ {aka ‘long long int’}
> > > > > [-Wformat=]
> > > > >  1316 |    printf("  %u: %" PRId64 "%s\n", menu.index, menu.value,
> > > > >       |           ^~~~~~~~~                            ~~~~~~~~~~
> > > > >       |                                                    |
> > > > >       |                                                    __s64 {aka
> > > > > long long int}
> > > > > In file included from yavta.c:26:
> > > > > /usr/include/inttypes.h:57:34: note: format string is defined here
> > > > >    57 | # define PRId64  __PRI64_PREFIX "d"
> > > >
> > > > I guess I should have expected this...
> > > >
> > > > I'm not sure if it'd be prettier but another option is to use the PRI*
> > > > macros and explicitly cast to a standard type.
> >
> > I would like to avoid
> >
> >   printf(" Hello %" PRId64 "\n", (uint64_t) value_s64);
> >
> > That looks very bad :)
>
> I actually prefer this. It doesn't look bad either IMO, apart from the PRI*
> macros that are always ugly, but most importantly you're explicitly using
> 64-bit types that work everywhere.

I am sending a v2, but it looks uglier (not that v1 was super beauty)


>
> >
> > I believe the current casting is the least of the two evils.
> >
> >
> > > >
> > > > Using the standard types in the V4L2 header would have avoided this issue.
> > > > I wonder if there's anything to be gained by using the kernel types.
> > >
> > > The kernel has defined __s64 as signed int int for a long time now, on
> > > all architectures, at least since
> > >
> > > commit 0c79a8e29b5fcbcbfd611daf9d500cfad8370fcf
> > > Author: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> > > Date:   Thu Jan 23 15:53:43 2014 -0800
> > >
> > >     asm/types.h: Remove include/asm-generic/int-l64.h
> > >
> > > which was merged in v3.14.
> > >
> > > According to https://buildd.debian.org/status/package.php?p=yavta,
> > > however, __s64 seems to be defined as long int on some platforms.
> > >
> > > /me is puzzled
> >
> > It does not help that __s64 is long long int and PRId64 is "d". I
> > guess we can say that inttypes and kernel types do not play along?
>
> I haven't encountered this issue in the past but I also haven't tried
> compiling for odd architectures.

Just to make it explicit

PRId64 == ld and _s64 == long long int

is a problem also for x86_64

>
> >
> > I guess we need kerntypes.h with proper KPRId64 but that is probably
> > out of scope here.
>
> This could even depend on the compiler.
>
> I wonder why we aren't using
>
>         typedef uint64_t __u64;
>
> in kernel UAPI headers instead. Including inttypes.h should not be an issue
> in 2023 anymore.
>
> This problem is certainly wider in scope than yavta.
>
> --
> Regards,
>
> Sakari Ailus



-- 
Ricardo Ribalda




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux