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: Should undefined behavior be encouraged in Emacs? Date: Sun, 02 Oct 2011 18:39:25 -0700 Organization: UCLA Computer Science Department Message-ID: <4E89124D.8070405@cs.ucla.edu> 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 1317605979 12489 80.91.229.12 (3 Oct 2011 01:39:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 3 Oct 2011 01:39:39 +0000 (UTC) To: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 03 03:39:35 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 1RAXVF-0002Nc-9R for ged-emacs-devel@m.gmane.org; Mon, 03 Oct 2011 03:39:33 +0200 Original-Received: from localhost ([::1]:58735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAXVE-0007Tq-B3 for ged-emacs-devel@m.gmane.org; Sun, 02 Oct 2011 21:39:32 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:57734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAXVB-0007Ta-9G for emacs-devel@gnu.org; Sun, 02 Oct 2011 21:39:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RAXV9-0003B2-QX for emacs-devel@gnu.org; Sun, 02 Oct 2011 21:39:29 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:46688) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAXV9-0003Ax-Ev for emacs-devel@gnu.org; Sun, 02 Oct 2011 21:39:27 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 4D97FA6003E for ; Sun, 2 Oct 2011 18:39:26 -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 mlLcoiDo4ICw for ; Sun, 2 Oct 2011 18:39:25 -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 B7918A60002 for ; Sun, 2 Oct 2011 18:39:25 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 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:144531 Archived-At: Bug#9642 has raised a question about Emacs design philosophy. Some Emacs built-ins treat an out-of-range argument as the nearest value in range. For example, (goto-char -5) acts like (goto-char 1), and (make-overlay -5 1) acts like (make-overlay 1 1), because -5 is out of the range of valid buffer positions. Other built-ins signal an exception: for example, (aref "abc" -5) signals an error, and (forward-char -5) signals an error at buffer start. And still others wrap around: for example, (- most-negative-fixnum) yields most-negative-fixnum. A recent comment in Bug#9642 advocates another approach: undefined behavior. For example, it proposes that move-overlay should have undefined behavior when given arguments like -5 that are out of range. In other words, (move-overlay OVERLAY -5 1) might signal an error, or substitute an in-range value, or wrap around, or return a data structure that subtly violates some other guarantee made by Emacs; or it might do one of these things sometimes and another at other times. In short, undefined behavior means that move-overlay might do *anything* when given out-of-range arguments. The argument given for undefined behavior is that it simplifies maintenance of Emacs internals. My impression is that Emacs built-ins are generally supposed to have defined behavior, so that Emacs is easier to use reliably. But another developer apparently disagrees, so thought I'd ask on emacs-devel for further comments. Here's the a pointer to the abovementioned comment: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9642#23