All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t
@ 2017-11-06  0:56 Brad Smith
  2017-11-06 10:51 ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Brad Smith @ 2017-11-06  0:56 UTC (permalink / raw)
  To: qemu-devel

Define TIME_MAX to LLONG_MAX for OpenBSD since OpenBSD uses 64-bit time_t.

Signed-off-by: Brad Smith <brad@comstyle.com>


diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 6855b94bbf..824714049b 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -132,8 +132,12 @@ extern int daemon(int, int);
 #define ESHUTDOWN 4099
 #endif
 #ifndef TIME_MAX
+#ifdef __OpenBSD__
+#define TIME_MAX LLONG_MAX
+#else
 #define TIME_MAX LONG_MAX
 #endif
+#endif
 
 /* HOST_LONG_BITS is the size of a native pointer in bits. */
 #if UINTPTR_MAX == UINT32_MAX

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t
  2017-11-06  0:56 [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t Brad Smith
@ 2017-11-06 10:51 ` Peter Maydell
  2017-11-06 11:26   ` Daniel P. Berrange
  2017-11-06 17:21   ` Kamil Rytarowski
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Maydell @ 2017-11-06 10:51 UTC (permalink / raw)
  To: Brad Smith; +Cc: QEMU Developers

On 6 November 2017 at 00:56, Brad Smith <brad@comstyle.com> wrote:
> Define TIME_MAX to LLONG_MAX for OpenBSD since OpenBSD uses 64-bit time_t.
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
>
>
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 6855b94bbf..824714049b 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -132,8 +132,12 @@ extern int daemon(int, int);
>  #define ESHUTDOWN 4099
>  #endif
>  #ifndef TIME_MAX
> +#ifdef __OpenBSD__
> +#define TIME_MAX LLONG_MAX
> +#else
>  #define TIME_MAX LONG_MAX
>  #endif
> +#endif

I'm not really a fan of adding new OS-specific #ifdefs --
what if one of the other BSDs uses or switches to 64-bit
time_t for 32-bit platforms? Is there some way we can detect
this generically at compile time (possibly in configure) ?

thanks
-- PMM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t
  2017-11-06 10:51 ` Peter Maydell
@ 2017-11-06 11:26   ` Daniel P. Berrange
  2017-11-06 17:41     ` Paolo Bonzini
  2017-11-06 17:21   ` Kamil Rytarowski
  1 sibling, 1 reply; 6+ messages in thread
From: Daniel P. Berrange @ 2017-11-06 11:26 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Brad Smith, QEMU Developers

On Mon, Nov 06, 2017 at 10:51:16AM +0000, Peter Maydell wrote:
> On 6 November 2017 at 00:56, Brad Smith <brad@comstyle.com> wrote:
> > Define TIME_MAX to LLONG_MAX for OpenBSD since OpenBSD uses 64-bit time_t.
> >
> > Signed-off-by: Brad Smith <brad@comstyle.com>
> >
> >
> > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> > index 6855b94bbf..824714049b 100644
> > --- a/include/qemu/osdep.h
> > +++ b/include/qemu/osdep.h
> > @@ -132,8 +132,12 @@ extern int daemon(int, int);
> >  #define ESHUTDOWN 4099
> >  #endif
> >  #ifndef TIME_MAX
> > +#ifdef __OpenBSD__
> > +#define TIME_MAX LLONG_MAX
> > +#else
> >  #define TIME_MAX LONG_MAX
> >  #endif
> > +#endif
> 
> I'm not really a fan of adding new OS-specific #ifdefs --
> what if one of the other BSDs uses or switches to 64-bit
> time_t for 32-bit platforms? Is there some way we can detect
> this generically at compile time (possibly in configure) ?

You could use a pair of compile time asserts to figure it out.

Would need one compile test to check 32 vs 64 bit:

  #include <time.h>
  char time_t_64bit[sizeof(time_t) == 8 ? 1 : -1];

and a second to check signed vs unsigned:

  #include <time.h>
  char time_t_signed[(time_t) -1 < 0 ? 1 : -1];


Save each of these programs to the file $TMPC, and then run 'compile_object'
from configure. You then have a decision matrix for 4 different TIME_MAX
values to write into config-host.h.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t
  2017-11-06 10:51 ` Peter Maydell
  2017-11-06 11:26   ` Daniel P. Berrange
@ 2017-11-06 17:21   ` Kamil Rytarowski
  1 sibling, 0 replies; 6+ messages in thread
From: Kamil Rytarowski @ 2017-11-06 17:21 UTC (permalink / raw)
  To: Peter Maydell, Brad Smith; +Cc: QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 1051 bytes --]

On 06.11.2017 11:51, Peter Maydell wrote:
> On 6 November 2017 at 00:56, Brad Smith <brad@comstyle.com> wrote:
>> Define TIME_MAX to LLONG_MAX for OpenBSD since OpenBSD uses 64-bit time_t.
>>
>> Signed-off-by: Brad Smith <brad@comstyle.com>
>>
>>
>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> index 6855b94bbf..824714049b 100644
>> --- a/include/qemu/osdep.h
>> +++ b/include/qemu/osdep.h
>> @@ -132,8 +132,12 @@ extern int daemon(int, int);
>>  #define ESHUTDOWN 4099
>>  #endif
>>  #ifndef TIME_MAX
>> +#ifdef __OpenBSD__
>> +#define TIME_MAX LLONG_MAX
>> +#else
>>  #define TIME_MAX LONG_MAX
>>  #endif
>> +#endif
> 
> I'm not really a fan of adding new OS-specific #ifdefs --
> what if one of the other BSDs uses or switches to 64-bit
> time_t for 32-bit platforms? Is there some way we can detect
> this generically at compile time (possibly in configure) ?
> 

NetBSD 32-bit ports switched to 64-bit in 2009. There are no longer
supported releases with 32-bit time_t.

> thanks
> -- PMM
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t
  2017-11-06 11:26   ` Daniel P. Berrange
@ 2017-11-06 17:41     ` Paolo Bonzini
  2017-11-23 15:31       ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2017-11-06 17:41 UTC (permalink / raw)
  To: Daniel P. Berrange, Peter Maydell; +Cc: QEMU Developers, Brad Smith

On 06/11/2017 12:26, Daniel P. Berrange wrote:
> On Mon, Nov 06, 2017 at 10:51:16AM +0000, Peter Maydell wrote:
>> On 6 November 2017 at 00:56, Brad Smith <brad@comstyle.com> wrote:
>>> Define TIME_MAX to LLONG_MAX for OpenBSD since OpenBSD uses 64-bit time_t.
>>>
>>> Signed-off-by: Brad Smith <brad@comstyle.com>
>>>
>>>
>>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>>> index 6855b94bbf..824714049b 100644
>>> --- a/include/qemu/osdep.h
>>> +++ b/include/qemu/osdep.h
>>> @@ -132,8 +132,12 @@ extern int daemon(int, int);
>>>  #define ESHUTDOWN 4099
>>>  #endif
>>>  #ifndef TIME_MAX
>>> +#ifdef __OpenBSD__
>>> +#define TIME_MAX LLONG_MAX
>>> +#else
>>>  #define TIME_MAX LONG_MAX
>>>  #endif
>>> +#endif
>>
>> I'm not really a fan of adding new OS-specific #ifdefs --
>> what if one of the other BSDs uses or switches to 64-bit
>> time_t for 32-bit platforms? Is there some way we can detect
>> this generically at compile time (possibly in configure) ?
> 
> You could use a pair of compile time asserts to figure it out.
> 
> Would need one compile test to check 32 vs 64 bit:
> 
>   #include <time.h>
>   char time_t_64bit[sizeof(time_t) == 8 ? 1 : -1];
> 
> and a second to check signed vs unsigned:
> 
>   #include <time.h>
>   char time_t_signed[(time_t) -1 < 0 ? 1 : -1];
> 
> 
> Save each of these programs to the file $TMPC, and then run 'compile_object'
> from configure. You then have a decision matrix for 4 different TIME_MAX
> values to write into config-host.h.

What about

#define type_max(t)                   \
    ((t) -1 > 0                       \
     ? (t)~0                          \
     : (((t)1) <<                     \
         (sizeof(t) * 8 - 1)) - 1)    \

#define TIME_MAX type_max(time_t)

?  We don't need it to be a cpp constant, do we?  Or if we did, we could
assume it to be signed, it's enough for the three users.

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t
  2017-11-06 17:41     ` Paolo Bonzini
@ 2017-11-23 15:31       ` Peter Maydell
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2017-11-23 15:31 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Daniel P. Berrange, QEMU Developers, Brad Smith

On 6 November 2017 at 17:41, Paolo Bonzini <pbonzini@redhat.com> wrote:
> What about
>
> #define type_max(t)                   \
>     ((t) -1 > 0                       \
>      ? (t)~0                          \
>      : (((t)1) <<                     \
>          (sizeof(t) * 8 - 1)) - 1)    \
>
> #define TIME_MAX type_max(time_t)
>
> ?  We don't need it to be a cpp constant, do we?  Or if we did, we could
> assume it to be signed, it's enough for the three users.

GCC doesn't like this phrasing, it complains
qmp.c: In function ‘qmp_expire_password’:
qmp.c:334:89: error: integer overflow in expression [-Werror=overflow]

because of the shift into the sign bit. Instead we can borrow the
TYPE_MAXIMUM macro from gnulib, which uses basically the same
approach but avoids the UB and the compiler warning. I'll send
a patch in a bit.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-23 15:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-06  0:56 [Qemu-devel] [PATCH] osdep: Deal with TIME_MAX and OpenBSD 64-bit time_t Brad Smith
2017-11-06 10:51 ` Peter Maydell
2017-11-06 11:26   ` Daniel P. Berrange
2017-11-06 17:41     ` Paolo Bonzini
2017-11-23 15:31       ` Peter Maydell
2017-11-06 17:21   ` Kamil Rytarowski

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.