From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: Removing some workarounds for big integers Date: Sun, 9 Aug 2020 17:39:11 +0200 Message-ID: References: <86d0uck5o0.fsf@gmail.com> <15786884-92c4-efb0-58d3-a6ec6726a0fe@cs.ucla.edu> <86lg02our6.fsf@gmail.com> <2cad6bf3-e0ef-eada-41d8-00d13ea814e4@cs.ucla.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37696"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Andy Moreton , Emacs developers To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Aug 09 17:40:01 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k4nQX-0009fj-GW for ged-emacs-devel@m.gmane-mx.org; Sun, 09 Aug 2020 17:40:01 +0200 Original-Received: from localhost ([::1]:32916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k4nQW-0003Ki-Cj for ged-emacs-devel@m.gmane-mx.org; Sun, 09 Aug 2020 11:40:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k4nPx-0002uf-CF for emacs-devel@gnu.org; Sun, 09 Aug 2020 11:39:25 -0400 Original-Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]:41287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k4nPv-0002qQ-Lx for emacs-devel@gnu.org; Sun, 09 Aug 2020 11:39:25 -0400 Original-Received: by mail-ot1-x32a.google.com with SMTP id a65so5371697otc.8 for ; Sun, 09 Aug 2020 08:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=L0ndjGWi07DE+GmqRIZkhLaJfjAsR06nyQksXIQtxWc=; b=QvHj0IKlDpArzDlD+UbZpkh9wN6QO8DFRhIVCcpQxk8XCXGT9dtaLAKfPgOYqt28Xm d15wMsxqIfVEBhMo2dyuWDuPTy6b9oy/diYhIaO7Mow7sJguVKIvE0GR1kp8y/IVPGW7 Y7wmj0TKy73m7LSzavJYE59FPwzE4uFc/H8JjfbbyDKVAHl7GuK2KpJcS1UPn8Swac0z NPTpy/luQUoSzXz9zzKZBjN2oshMML9XsbA00lgWWU43cEpr0ma2HdO/Vkom67lW4flJ oj5pA++AVVDK9ik5g4pSjdEk1oCajVQFMLEfxHfzN16c9wbPM/L1mw/KqTV1GZtCfRmb ElqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=L0ndjGWi07DE+GmqRIZkhLaJfjAsR06nyQksXIQtxWc=; b=Xv45NILpoSvxztyPumt0p+STSb7MPYqjHwCqt3IzZVMUxTynns8+ozzLw/iGq64Kxz TiZ2kQ0f4JKCOJ3d5HmXTG+ZxQLMSiuo8RCcCFYm6UXz6Kjx4TntXogGf7k2v6iV6jK+ Il7j/WUbihZNVH5LtbL2c4J6vQNFukS2SUm74wB1NFf3OffHtK7KvRnYfZjCMwRjS2Dx 2lZY1jMkgvvoRcX1qVR9S9+d0FME2uXV7R5sWanuk/O4UBTcowmsqd4PNsDpWprMBm1b 9rza0mSgjZNsXkpyVpIOsnBmRZE0Wdi+ZCSIshDte8SDkjR7V3MiidUc7bCf1pbOSuf6 pg1Q== X-Gm-Message-State: AOAM531iC8jzk173KSN71YwjLud6xAkdcokoQLSHGkWy/9no+gW9B4cN uB2VFaA0mF0yBOEtlufuK/tqWwlAZhTUpHCpypg= X-Google-Smtp-Source: ABdhPJwu1l3mziwIIFqkWR76DczSwLOYKJ/JRhwFeBO8YssUA2jjZ2Q6+619ksKs7v6m/4XaKN9628ZAyIQ32xeE3RA= X-Received: by 2002:a9d:170c:: with SMTP id i12mr19894745ota.36.1596987562208; Sun, 09 Aug 2020 08:39:22 -0700 (PDT) In-Reply-To: <2cad6bf3-e0ef-eada-41d8-00d13ea814e4@cs.ucla.edu> Received-SPF: pass client-ip=2607:f8b0:4864:20::32a; envelope-from=p.stephani2@gmail.com; helo=mail-ot1-x32a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:253546 Archived-At: Am Mi., 5. Aug. 2020 um 08:11 Uhr schrieb Paul Eggert : > > On 8/1/20 1:09 PM, Philipp Stephani wrote: > > Am Mo., 22. Apr. 2019 um 20:45 Uhr schrieb Paul Eggert : > >> > >> 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, Yeah, good point, I forgot about the annoying behavior of the ternary operator. > > 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. I wouldn't agree to that. The large advantage of packaging the conversion up into a single macro is that the range check is always correct and only needs to be coded once. Repeating the range check for each caller is rather error-prone. So I think a void-returning macro makes sense. It wouldn't even need another argument, as the type follows from the destination. (At least if __typeof__ is available.)