From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2623 invoked by alias); 10 Apr 2017 03:56:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 1492 invoked by uid 89); 10 Apr 2017 03:54:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=management X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Apr 2017 03:54:51 +0000 Received: by simark.ca (Postfix, from userid 33) id 79EE81E7F5; Sun, 9 Apr 2017 23:54:51 -0400 (EDT) To: Tom Tromey Subject: Re: [RFA 06/14] Remove cleanup_iconv X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 10 Apr 2017 03:56:00 -0000 From: Simon Marchi Cc: gdb-patches@sourceware.org In-Reply-To: <20170408201208.2672-7-tom@tromey.com> References: <20170408201208.2672-1-tom@tromey.com> <20170408201208.2672-7-tom@tromey.com> Message-ID: <20f3123507be4351238bda8e0141958f@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.4 X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00224.txt.bz2 On 2017-04-08 16:12, Tom Tromey wrote: > --- a/gdb/charset.c > +++ b/gdb/charset.c > @@ -481,14 +481,33 @@ host_hex_value (char c) > > /* Public character management functions. */ > > -/* A cleanup function which is run to close an iconv descriptor. */ > - > -static void > -cleanup_iconv (void *p) > +class iconv_wrapper > { > - iconv_t *descp = (iconv_t *) p; > - iconv_close (*descp); > -} > +public: > + > + iconv_wrapper (const char *from, const char *to) > + { > + m_desc = iconv_open (to, from); > + if (m_desc == (iconv_t) -1) > + perror_with_name (_("Converting character sets")); > + } > + > + ~iconv_wrapper () > + { > + if (m_desc != (iconv_t) -1) > + iconv_close (m_desc); From what I understand about C++ constructors and destructors, the check for -1 is unnecessary. The destructor will only be called if the constructor ran to completion. If the constructor ran to completion (didn't throw), m_desc won't be -1. Otherwise, LGTM. Thanks, Simon