This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/6] nptl: Convert tst-cond11.c to use libsupport


On Wednesday 03 April 2019 at 09:18:56 +0700, Adhemerval Zanella wrote:
> On 29/03/2019 01:31, Mike Crowe wrote:
> > diff --git a/support/timespec.h b/support/timespec.h
> > new file mode 100644
> > index 0000000..d439d62
> > --- /dev/null
> > +++ b/support/timespec.h
> > @@ -0,0 +1,115 @@
[...]
> > +static inline void
> > +timespec_sub (struct timespec *diff, const struct timespec *left,
> > +	      const struct timespec *right)
> > +{
> > +  diff->tv_sec = left->tv_sec - right->tv_sec;
> > +  diff->tv_nsec = left->tv_nsec - right->tv_nsec;
> > +
> > +  if (diff->tv_nsec < 0)
> > +    {
> > +      --diff->tv_sec;
> > +      diff->tv_nsec += 1000000000;
> > +    }
> > +}
> > +
> 
> I think we should handle overflow in such tests and assuming always signed
> time_t we can use a simplified version of gnulib (if I get everything right):
> 
> ---
> void
> timespec_subtract (struct timespec *r, const struct timespec *a,
>                    const struct timespec *b)
> { 
>   time_t rs = a->tv_sec;
>   time_t bs = b->tv_sec;
>   long int ns = a->tv_nsec - b->tv_nsec;
>   long int rns = ns;
>   
>   if (ns < 0)
>     { 
>       rns = ns + TIMESPEC_HZ;
>       if (bs < TYPE_MAXIMUM (time_t))
>         bs++;
>       else
>         {  
>           rs = TYPE_MINIMUM (time_t);
>           rns = 0;
>         }
>    }
>   
>   if (!__builtin_sub_overflow (rs, bs, &rs))
>     rs -= bs;
>   else
>     { 
>       if (rs < 0)
>         {  
>           rs = TYPE_MINIMUM (time_t);
>           rns = 0;
>         }
>       else 
>         {  
>           rs = TYPE_MAXIMUM (time_t);
>           rns = TIMESPEC_HZ - 1;
>         }
>     }
> 
>   *r = (struct timespec) { ns, rns };
> }

That seems to rely on macros from include/intprops.h anyway, so is there
any disadvantage in just using the gnulib version as it stands (along with
a suitable definition of TIMESPEC_HZ)?

But, having said that, this code from gnulib is GPLv3 (and it always has
been), whereas glibc is LGPLv2.1. Surely this means that we can't just copy
the code across?

Mike.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]