This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 06/14] Remove cleanup_iconv


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]