From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jim Meyering Newsgroups: gmane.emacs.devel Subject: Re: emacs' turn: remove useless if-before-free tests Date: Sun, 01 Jun 2008 16:22:37 +0200 Message-ID: <87k5h9grpu.fsf@rho.meyering.net> References: <87fxryjv2n.fsf@rho.meyering.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1212330179 9387 80.91.229.12 (1 Jun 2008 14:22:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Jun 2008 14:22:59 +0000 (UTC) Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 01 16:23:41 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K2oTC-0005wK-Jc for ged-emacs-devel@m.gmane.org; Sun, 01 Jun 2008 16:23:38 +0200 Original-Received: from localhost ([127.0.0.1]:57334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2oSQ-0006Fp-FO for ged-emacs-devel@m.gmane.org; Sun, 01 Jun 2008 10:22:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K2oSL-0006CB-CR for emacs-devel@gnu.org; Sun, 01 Jun 2008 10:22:45 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K2oSJ-00068K-6r for emacs-devel@gnu.org; Sun, 01 Jun 2008 10:22:44 -0400 Original-Received: from [199.232.76.173] (port=45076 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2oSJ-00068A-4L for emacs-devel@gnu.org; Sun, 01 Jun 2008 10:22:43 -0400 Original-Received: from smtp3-g19.free.fr ([212.27.42.29]:45225) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K2oSF-0007fV-6T; Sun, 01 Jun 2008 10:22:39 -0400 Original-Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id 7B9B617B53D; Sun, 1 Jun 2008 16:22:38 +0200 (CEST) Original-Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp3-g19.free.fr (Postfix) with ESMTP id 6592E17B531; Sun, 1 Jun 2008 16:22:38 +0200 (CEST) Original-Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id E1A3C38445; Sun, 1 Jun 2008 16:22:37 +0200 (CEST) In-Reply-To: (Richard M. Stallman's message of "Sun, 01 Jun 2008 10:03:01 -0400") Original-Lines: 41 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:98186 Archived-At: Richard M Stallman wrote: > Given that most Emacs code calls xfree rather than free, there are not > many of these if statements, and we rarely add any. > Why remove them? Why *not* remove them? I find that removing the inherent duplication is safe (mechanical), and makes the code more readable and more maintainable. For example, - if (x_customization_string) - free (x_customization_string); + free (x_customization_string); - if (fdp->infname != NULL) free (fdp->infname); - if (fdp->infabsname != NULL) free (fdp->infabsname); - if (fdp->infabsdir != NULL) free (fdp->infabsdir); - if (fdp->taggedfname != NULL) free (fdp->taggedfname); - if (fdp->prop != NULL) free (fdp->prop); + free (fdp->infname); + free (fdp->infabsname); + free (fdp->infabsdir); + free (fdp->taggedfname); + free (fdp->prop); Another advantage is that readers won't wonder why the code is performing what has long been a useless test -- and then re-read to ensure that the tested expression and the free argument are properly related. POSIX requires that free(NULL) be a no-op. The same arguments hold for xfree, once it has been modified to accept NULL like free does: - if (font->bounds.rows[i]) - xfree (font->bounds.rows[i]); + xfree (font->bounds.rows[i]); - if (f->output_data.x->saved_menu_event) - xfree (f->output_data.x->saved_menu_event); - + xfree (f->output_data.x->saved_menu_event);