From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: size_t vs EMACS_INT Date: Fri, 15 Jul 2011 14:52:56 -0700 Organization: UCLA Computer Science Department Message-ID: <4E20B6B8.6030606@cs.ucla.edu> References: <8362n4hwny.fsf@gnu.org> <4E1FE8F8.4050501@cs.ucla.edu> <834o2ohsku.fsf@gnu.org> <4E206D05.3030100@cs.ucla.edu> <83r55rh3ew.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1310766852 15316 80.91.229.12 (15 Jul 2011 21:54:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 15 Jul 2011 21:54:12 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 15 23:54:07 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QhqKl-0005Kr-1L for ged-emacs-devel@m.gmane.org; Fri, 15 Jul 2011 23:54:07 +0200 Original-Received: from localhost ([::1]:45333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhqKj-00014f-OW for ged-emacs-devel@m.gmane.org; Fri, 15 Jul 2011 17:54:06 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:43631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhqJl-0000rH-Ll for emacs-devel@gnu.org; Fri, 15 Jul 2011 17:53:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QhqJi-0007pR-V4 for emacs-devel@gnu.org; Fri, 15 Jul 2011 17:53:05 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:46857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhqJg-0007oW-Ik; Fri, 15 Jul 2011 17:53:00 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id F271239E80F0; Fri, 15 Jul 2011 14:52:57 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pnQDVoZgj-I0; Fri, 15 Jul 2011 14:52:57 -0700 (PDT) Original-Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 4A57139E80E0; Fri, 15 Jul 2011 14:52:57 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 In-Reply-To: <83r55rh3ew.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:142035 Archived-At: On 07/15/11 10:14, Eli Zaretskii wrote: > ptrdiff_t should do, right? If so, let's use that. Yes, thanks, that sounds like the best way to go. >> > A lot of Emacs code assumes that MOST_POSITIVE_FIXNUM is much >> > less than TYPE_MAXIMUM (EMACS_INT), and any change to that assumption >> > would require a significant rewrite of the Emacs internals. > Can you show examples of these assumptions? The most central examples are the integer-extraction macros in lisp.h, e.g., make_number, XINT. Presumably these could be changed if we take the big step of adopting some other implementation strategy for Emacs integers, such that XINT (foo) could yield TYPE_MAXIMUM (EMACS_INT). But then we'd have to deal with examples like the following, in Fforward_char: EMACS_INT new_point = PT + XINT (n); This code is currently safe, since C code can always safely add two Emacs fixnums, and the addition can't possibly overflow at the C level. But if fixnums could equal TYPE_MAXIMUM (EMACS_INT), this code would be unsafe and we would have to add a run-time check for integer overflow. There are many more examples like this, not all of them as obvious as the above. Here's one, from Frem: XSETINT (val, XINT (x) % XINT (y)); If XINT (x) could equal TYPE_MINIMUM (EMACS_INT), then this would dump core on an x86 when XINT (y) == -1, because INT_MIN % -1 dumps core on the x86 (the C standard allows this, alas). However, since XINT (x) cannot possibly equal TYPE_MINIMUM (EMACS_INT), Emacs is currently safe from this problem, and we don't need to insert a run-time check here.