From patchwork Tue Apr 11 15:01:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 19970 Received: (qmail 37446 invoked by alias); 11 Apr 2017 15:21:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 37094 invoked by uid 89); 11 Apr 2017 15:21:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=5146 X-HELO: gproxy5.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 15:21:20 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 23DA9141BED for ; Tue, 11 Apr 2017 09:01:24 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 731L1v00r2f2jeq0131PeW; Tue, 11 Apr 2017 09:01:24 -0600 X-Authority-Analysis: v=2.2 cv=VKStp5HX c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=FGQ-QrHLVTbHYoE2rQ0A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-65-226.hlrn.qwest.net ([75.166.65.226]:50042 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cxxIG-0007Ml-88; Tue, 11 Apr 2017 09:01:20 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 06/17] Remove cleanup_iconv Date: Tue, 11 Apr 2017 09:01:01 -0600 Message-Id: <20170411150112.23207-7-tom@tromey.com> In-Reply-To: <20170411150112.23207-1-tom@tromey.com> References: <20170411150112.23207-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cxxIG-0007Ml-88 X-Source-Sender: 75-166-65-226.hlrn.qwest.net (bapiya.Home) [75.166.65.226]:50042 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This introduces a new "iconv_wrapper" class, to be used in convert_between_encodings. This allows the removal of cleanup_iconv. gdb/ChangeLog 2017-04-11 Tom Tromey * charset.c (iconv_wrapper): New class. (cleanup_iconv): Remove. (convert_between_encodings): Use it. --- gdb/ChangeLog | 6 ++++++ gdb/charset.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1c76edb..c50eaa8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2017-04-11 Tom Tromey + * charset.c (iconv_wrapper): New class. + (cleanup_iconv): Remove. + (convert_between_encodings): Use it. + +2017-04-11 Tom Tromey + * symfile.h (increment_reading_symtab): Update type. * symfile.c (decrement_reading_symtab): Remove. (increment_reading_symtab): Return a scoped_restore_tmpl. diff --git a/gdb/charset.c b/gdb/charset.c index 8302c59..a6da512 100644 --- a/gdb/charset.c +++ b/gdb/charset.c @@ -481,14 +481,32 @@ 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 () + { + iconv_close (m_desc); + } + + size_t convert (ICONV_CONST char **inp, size_t *inleft, char **outp, + size_t *outleft) + { + return iconv (m_desc, inp, inleft, outp, outleft); + } + +private: + + iconv_t m_desc; +}; void convert_between_encodings (const char *from, const char *to, @@ -496,8 +514,6 @@ convert_between_encodings (const char *from, const char *to, int width, struct obstack *output, enum transliterations translit) { - iconv_t desc; - struct cleanup *cleanups; size_t inleft; ICONV_CONST char *inp; unsigned int space_request; @@ -509,10 +525,7 @@ convert_between_encodings (const char *from, const char *to, return; } - desc = iconv_open (to, from); - if (desc == (iconv_t) -1) - perror_with_name (_("Converting character sets")); - cleanups = make_cleanup (cleanup_iconv, &desc); + iconv_wrapper desc (from, to); inleft = num_bytes; inp = (ICONV_CONST char *) bytes; @@ -531,7 +544,7 @@ convert_between_encodings (const char *from, const char *to, outp = (char *) obstack_base (output) + old_size; outleft = space_request; - r = iconv (desc, &inp, &inleft, &outp, &outleft); + r = desc.convert (&inp, &inleft, &outp, &outleft); /* Now make sure that the object on the obstack only includes bytes we have converted. */ @@ -583,8 +596,6 @@ convert_between_encodings (const char *from, const char *to, } } } - - do_cleanups (cleanups); }