all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: Andy Moreton <andrewjmoreton@gmail.com>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: Removing some workarounds for big integers
Date: Tue, 4 Aug 2020 23:11:31 -0700	[thread overview]
Message-ID: <2cad6bf3-e0ef-eada-41d8-00d13ea814e4@cs.ucla.edu> (raw)
In-Reply-To: <CAArVCkSZzv_GsdnpHbLGAjHu0eZTvR27k05hvhp+QDb-cLU=5w@mail.gmail.com>

On 8/1/20 1:09 PM, Philipp Stephani wrote:
> Am Mo., 22. Apr. 2019 um 20:45 Uhr schrieb Paul Eggert <eggert@cs.ucla.edu>:
>>
>> On 4/22/19 9:59 AM, Philipp Stephani wrote:
>>>
>>>> +#define INTEGER_TO_INT(num, type)                                              \
>>>> +  (TYPE_SIGNED (type)                                                          \
>>>> +     ? ranged_integer_to_int ((num), TYPE_MINIMUM (type), TYPE_MAXIMUM (type)) \
>>>> +     : ranged_integer_to_uint ((num), TYPE_MINIMUM (type)))
>>>>                                         ^^^^^^^^^^^^
>>>> This should be TYPE_MAXIMUM.
>>>
>>> Thanks, fixed
>>>
>> More important, INTEGER_TO_INT's type conversion messes up and can cause
>> a signal on picky platforms.
> 
> How so?

The type conversion is messed up because on conventional platforms 
INTEGER_TO_INT returns a value of uintmax_t, which means that an expression like 
'INTEGER_TO_INT (n, t) < 0' will always be false, even if N is negative and T is 
a signed type.

The "picky platform" is one where conversion from unsigned to signed signals 
when the value is out of range for the signed type; this behavior is allowed by 
POSIX and the C standard and I imagine some debugging implementations might 
check for it. On these implementations,

To work around this problem, the macro could have another argument, being the 
lvalue destination; that would avoid these problems. However, it'd be more 
awkward to use. At some point it's easier to avoid the macro and use the 
underlying functions.



  reply	other threads:[~2020-08-05  6:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-20 21:43 Removing some workarounds for big integers Philipp
2018-08-20 21:55 ` John Wiegley
2018-08-20 22:57 ` Andy Moreton
2018-09-21 19:32   ` Philipp Stephani
2018-09-21 23:12     ` Paul Eggert
2019-04-22 15:40       ` Philipp Stephani
2019-04-22 16:43         ` Andy Moreton
2019-04-22 16:59           ` Philipp Stephani
2019-04-22 18:45             ` Paul Eggert
2020-08-01 20:09               ` Philipp Stephani
2020-08-05  6:11                 ` Paul Eggert [this message]
2020-08-09 15:39                   ` Philipp Stephani
2020-08-09 16:13                     ` Philipp Stephani
2020-08-09 17:04                       ` Stefan Monnier
2020-08-09 17:26                         ` Paul Eggert
2020-10-13 19:10                           ` Philipp Stephani
2019-04-22 18:57         ` Paul Eggert
2020-08-01 20:15           ` Philipp Stephani

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=2cad6bf3-e0ef-eada-41d8-00d13ea814e4@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=andrewjmoreton@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=p.stephani2@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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.