changeset 28850:445e5ac1f58d

in unwind_action objects, capture variables in lambda expressions when possible Files affected: call-stack.cc, graphics.cc, input.cc, jsonencode.cc, oct-hist.cc, rand.cc, strfns.cc, sysdep.cc, toplev.cc, __delaunayn__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, lo-sysdep.cc, oct-glob.cc, oct-string.cc, and url-transfer.cc.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Oct 2020 12:58:12 -0400
parents 8b0675c2cfe0
children 1ac5a76ae91d
files libinterp/corefcn/call-stack.cc libinterp/corefcn/graphics.cc libinterp/corefcn/input.cc libinterp/corefcn/jsonencode.cc libinterp/corefcn/oct-hist.cc libinterp/corefcn/rand.cc libinterp/corefcn/strfns.cc libinterp/corefcn/sysdep.cc libinterp/corefcn/toplev.cc libinterp/dldfcn/__delaunayn__.cc libinterp/dldfcn/__voronoi__.cc libinterp/dldfcn/audiodevinfo.cc libinterp/dldfcn/audioread.cc libinterp/dldfcn/convhulln.cc liboctave/system/lo-sysdep.cc liboctave/util/oct-glob.cc liboctave/util/oct-string.cc liboctave/util/url-transfer.cc
diffstat 18 files changed, 34 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/call-stack.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/call-stack.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -974,8 +974,7 @@
 
         push (tmp_scope);
 
-        octave::unwind_action restore_scope
-          ([] (auto self) { self->pop (); }, this);
+        unwind_action restore_scope ([this] (void) { pop (); });
 
         feval ("load", octave_value (file_name), 0);
 
--- a/libinterp/corefcn/graphics.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/graphics.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -1947,8 +1947,7 @@
   // their handlevisibility property set to "callback" to be visible.
 
   octave::unwind_action executing_callbacks_cleanup
-    ([] (auto old_callback_props, auto &self)
-      { old_callback_props->erase (self); }, &executing_callbacks, this);
+    ([this] () { executing_callbacks.erase (this); });
 
   if (! executing_callbacks.contains (this))
     {
--- a/libinterp/corefcn/input.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/input.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -927,10 +927,7 @@
                  encoding.c_str (), std::strerror (errno));
 
         octave::unwind_action free_utf8_str
-          ([] (const auto utf8_str_ptr)
-           {
-             ::free (utf8_str_ptr);
-           }, static_cast<void *> (utf8_str));
+          ([utf8_str] () { ::free (utf8_str); });
 
         src_str = std::string (reinterpret_cast<char *> (utf8_str), length);
       }
--- a/libinterp/corefcn/jsonencode.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/jsonencode.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -411,7 +411,7 @@
     // "Octave:classdef-to-struct" warning and re-enable it.
     {
       octave::unwind_action restore_warning_state
-        ([] (const auto& old_warning_state)
+        ([] (const octave_value_list& old_warning_state)
          {
            set_warning_state (old_warning_state);
          }, set_warning_state ("Octave:classdef-to-struct", "off"));
@@ -422,7 +422,7 @@
   else if (obj.isobject ())
     {
       octave::unwind_action restore_warning_state
-        ([] (const auto& old_warning_state)
+        ([] (const octave_value_list& old_warning_state)
          {
            set_warning_state (old_warning_state);
          }, set_warning_state ("Octave:classdef-to-struct", "off"));
--- a/libinterp/corefcn/oct-hist.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/oct-hist.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -328,7 +328,7 @@
     bool numbered_output = nargout == 0;
 
     octave::unwind_action restore_history_filename
-      ([] (const auto& old_filename)
+      ([] (const std::string& old_filename)
        {
          command_history::set_file (old_filename);
        }, command_history::file ());
--- a/libinterp/corefcn/rand.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/rand.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -119,7 +119,7 @@
 
   // Restore current distribution on any exit.
   octave::unwind_action restore_distribution
-    ([] (const auto& old_distribution)
+    ([] (const std::string& old_distribution)
      {
        octave::rand::distribution (old_distribution);
      }, octave::rand::distribution ());
--- a/libinterp/corefcn/strfns.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/strfns.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -913,11 +913,7 @@
                codepage, std::strerror (errno));
     }
 
-  octave::unwind_action free_utf8_str
-    ([] (const auto utf8_str_ptr)
-     {
-       ::free (utf8_str_ptr);
-     }, static_cast<void *> (utf8_str));
+  octave::unwind_action free_utf8_str ([utf8_str] () { ::free (utf8_str); });
 
   octave_idx_type len = length;
 
@@ -968,10 +964,7 @@
     }
 
   octave::unwind_action free_native_bytes
-    ([] (const auto native_bytes_ptr)
-     {
-       ::free (native_bytes_ptr);
-     }, static_cast<void *> (native_bytes));
+    ([native_bytes] () { ::free (native_bytes); });
 
   octave_idx_type len = length;
 
--- a/libinterp/corefcn/sysdep.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/sysdep.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -719,11 +719,11 @@
     wchar_t *wmode = u8_to_wchar (mode);
 
     octave::unwind_action free_memory
-      ([] (const auto wcommand_ptr, const auto wmode_ptr)
+      ([wcommand, wmode] ()
        {
-         ::free (wcommand_ptr);
-         ::free (wmode_ptr);
-       }, static_cast<void *> (wcommand), static_cast<void *> (wmode));
+         ::free (wcommand);
+         ::free (wmode);
+       });
 
     if (wmode && wmode[0] && ! wmode[1])
       {
@@ -965,10 +965,7 @@
       return result;
 
     octave::unwind_action restore_keys
-      ([] (const auto& old_subkeys)
-       {
-         reg_close_key_wrapper (old_subkeys);
-       }, h_subkey);
+      ([h_subkey] () { reg_close_key_wrapper (h_subkey); });
 
     std::wstring wname = sys::u8_to_wstring (name);
     DWORD length = 0;
--- a/libinterp/corefcn/toplev.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/corefcn/toplev.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -282,10 +282,7 @@
 #endif
 
   octave::unwind_action restore_mask
-    ([] (const auto signal_mask_ptr)
-     {
-       restore_signal_mask (signal_mask_ptr);
-     }, get_signal_mask ());
+    ([] (void *mask) { restore_signal_mask (mask); }, get_signal_mask ());
 
   octave_unblock_async_signals ();
   octave_unblock_signal_by_name ("SIGTSTP");
--- a/libinterp/dldfcn/__delaunayn__.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/dldfcn/__delaunayn__.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -70,12 +70,6 @@
 #  endif
 
 static void
-close_fcn (FILE *f)
-{
-  std::fclose (f);
-}
-
-static void
 free_qhull_memory ()
 {
   qh_freeqhull (! qh_ALL);
@@ -178,7 +172,7 @@
         error ("__delaunayn__: unable to create temporary file for output");
 
       octave::unwind_action close_outfile
-        ([] (const auto file_ptr) { close_fcn (file_ptr); }, outfile);
+        ([outfile] () { std::fclose (outfile); });
 
       int exitcode = qh_new_qhull (dim, n, pt_array,
                                    ismalloc, flags, outfile, errfile);
--- a/libinterp/dldfcn/__voronoi__.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/dldfcn/__voronoi__.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -65,12 +65,6 @@
 #  endif
 
 static void
-close_fcn (FILE *f)
-{
-  std::fclose (f);
-}
-
-static void
 free_qhull_memory ()
 {
   qh_freeqhull (! qh_ALL);
@@ -169,8 +163,7 @@
   if (! outfile)
     error ("__voronoi__: unable to create temporary file for output");
 
-  octave::unwind_action close_outfile
-    ([] (const auto file_ptr) { close_fcn (file_ptr); }, outfile);
+  octave::unwind_action close_outfile ([outfile] () { std::fclose (outfile); });
 
   // qh_new_qhull command and points arguments are not const...
 
--- a/libinterp/dldfcn/audiodevinfo.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/dldfcn/audiodevinfo.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -1150,8 +1150,7 @@
   start = get_sample_number ();
   end = get_end_sample ();
 
-  octave::unwind_action stop_audioplayer
-    ([] (audioplayer * player) { player->stop (); }, this);
+  octave::unwind_action stop_audioplayer ([this] () { stop (); });
 
   for (unsigned int i = start; i < end; i += buffer_size)
     {
@@ -1823,8 +1822,7 @@
 
   unsigned int frames = seconds * get_fs ();
 
-  octave::unwind_action stop_audiorecorder
-    ([] (audiorecorder * recorder) { recorder->stop (); }, this);
+  octave::unwind_action stop_audiorecorder ([this] () { stop (); });
 
   for (unsigned int i = 0; i < frames; i += buffer_size)
     {
--- a/libinterp/dldfcn/audioread.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/dldfcn/audioread.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -88,8 +88,7 @@
     error ("audioread: failed to open input file '%s': %s",
            filename.c_str (), sf_strerror (file));
 
-  octave::unwind_action close_open_file
-    ([] (auto file_ptr) { sf_close (file_ptr); }, file);
+  octave::unwind_action close_open_file ([file] () { sf_close (file); });
 
   OCTAVE_LOCAL_BUFFER (double, data, info.frames * info.channels);
 
@@ -422,8 +421,7 @@
     error ("audiowrite: failed to open output file '%s': %s",
            filename.c_str (), sf_strerror (file));
 
-  octave::unwind_action close_open_file
-    ([] (auto file_ptr) { sf_close (file_ptr); }, file);
+  octave::unwind_action close_open_file ([file] () { sf_close (file); });
 
   sf_command (file, SFC_SET_NORM_DOUBLE, nullptr, SF_TRUE);
   sf_command (file, SFC_SET_CLIPPING, nullptr, SF_TRUE) ;
@@ -616,8 +614,7 @@
     error ("audioinfo: failed to open input file '%s': %s",
            filename.c_str (), sf_strerror (file));
 
-  octave::unwind_action close_open_file
-    ([] (auto file_ptr) { sf_close (file_ptr); }, file);
+  octave::unwind_action close_open_file ([file] () { sf_close (file); });
 
   octave_scalar_map result;
 
--- a/libinterp/dldfcn/convhulln.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/libinterp/dldfcn/convhulln.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -178,8 +178,7 @@
   if (! outfile)
     error ("convhulln: unable to create temporary file for output");
 
-  octave::unwind_action close_outfile
-    ([] (const auto file_ptr) { std::fclose (file_ptr); }, outfile);
+  octave::unwind_action close_outfile ([outfile] () { std::fclose (outfile); });
 
   // qh_new_qhull command and points arguments are not const...
 
--- a/liboctave/system/lo-sysdep.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/liboctave/system/lo-sysdep.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -431,10 +431,7 @@
 #if defined (OCTAVE_USE_WINDOWS_API)
       wchar_t *wnew_item = u8_to_wchar (new_item);
       octave::unwind_action free_new_item
-        ([] (const auto new_item_ptr)
-         {
-           std::free (new_item_ptr);
-         }, static_cast<void *> (new_item));
+        ([] (const wchar_t *ptr) { std::free (ptr); }, new_item);
 
       if (_wputenv (wnew_item) < 0)
         (*current_liboctave_error_handler) ("putenv (%s) failed", new_item);
--- a/liboctave/util/oct-glob.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/liboctave/util/oct-glob.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -81,10 +81,7 @@
       void *glob_info = octave_create_glob_info_struct ();
 
       octave::unwind_action cleanup_glob_info_struct
-        ([] (const auto glob_info_ptr)
-         { 
-           octave_destroy_glob_info_struct (glob_info_ptr);
-         }, glob_info);
+        ([glob_info] () { octave_destroy_glob_info_struct (glob_info); });
 
       for (int i = 0; i < npat; i++)
         {
@@ -159,10 +156,7 @@
       void *glob_info = octave_create_glob_info_struct ();
 
       octave::unwind_action cleanup_glob_info_struct
-        ([] (const auto glob_info_ptr)
-         { 
-           octave_destroy_glob_info_struct (glob_info_ptr);
-         }, glob_info);
+        ([glob_info] () { octave_destroy_glob_info_struct (glob_info); });
 
       for (int i = 0; i < npat; i++)
         {
--- a/liboctave/util/oct-string.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/liboctave/util/oct-string.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -517,10 +517,7 @@
     }
 
   octave::unwind_action free_native_str
-    ([] (const auto native_str_ptr)
-     {
-       ::free (native_str_ptr);
-     }, static_cast<void *> (native_str));
+    ([native_str] () { ::free (native_str); });
 
   std::string retval = std::string (native_str, length);
 
@@ -550,11 +547,7 @@
            who.c_str (), encoding.c_str (), std::strerror (errno));
     }
 
-  octave::unwind_action free_utf8_str
-    ([] (const auto utf8_str_ptr)
-     {
-       ::free (utf8_str_ptr);
-     }, static_cast<void *> (utf8_str));
+  octave::unwind_action free_utf8_str ([utf8_str] () { ::free (utf8_str); });
 
   std::string retval = std::string (reinterpret_cast<char *> (utf8_str), length);
 
@@ -601,10 +594,7 @@
                    who.c_str (), fallback.c_str (), std::strerror (errno));
 
               octave::unwind_action free_val_utf8
-                ([] (const auto val_utf8_ptr)
-                 {
-                   ::free (val_utf8_ptr);
-                 }, static_cast<void *> (val_utf8));
+                ([val_utf8] () { ::free (val_utf8); });
 
               out_str.append (reinterpret_cast<const char *> (val_utf8),
                               lengthp);
--- a/liboctave/util/url-transfer.cc	Sat Sep 19 12:09:57 2020 +0200
+++ b/liboctave/util/url-transfer.cc	Fri Oct 02 12:58:12 2020 -0400
@@ -449,10 +449,7 @@
       struct curl_slist *slist = nullptr;
 
       octave::unwind_action cleanup_slist
-        ([] (const auto slist_ptr)
-         { 
-           curl_slist_free_all (slist_ptr);
-         }, slist);
+        ([slist] () { curl_slist_free_all (slist); });
 
       std::string cmd = "rnfr " + oldname;
       slist = curl_slist_append (slist, cmd.c_str ());
@@ -620,10 +617,7 @@
       struct curl_slist *slist = nullptr;
 
       octave::unwind_action cleanup_slist
-        ([] (const auto slist_ptr)
-         { 
-           curl_slist_free_all (slist_ptr);
-         }, slist);
+        ([slist] () { curl_slist_free_all (slist); });
 
       slist = curl_slist_append (slist, "pwd");
       SETOPTR (CURLOPT_POSTQUOTE, slist);
@@ -715,10 +709,7 @@
       struct curl_slist *slist = nullptr;
 
       octave::unwind_action cleanup_slist
-        ([] (const auto slist_ptr)
-         { 
-           curl_slist_free_all (slist_ptr);
-         }, slist);
+        ([slist] () { curl_slist_free_all (slist); });
 
       if (param.numel () >= 2)
         {
@@ -746,10 +737,7 @@
       SETOPT (CURLOPT_URL, m_host_or_url.c_str ());
 
       octave::unwind_action cleanup_httppost
-        ([] (const auto httppost_ptr)
-         { 
-           curl_formfree (httppost_ptr);
-         }, post);
+        ([post] () { curl_formfree (post); });
 
       if (param.numel () >= 2)
         {
@@ -924,10 +912,7 @@
       struct curl_slist *slist = nullptr;
 
       octave::unwind_action cleanup_slist
-        ([] (const auto slist_ptr)
-         { 
-           curl_slist_free_all (slist_ptr);
-         }, slist);
+        ([slist] () { curl_slist_free_all (slist); });
 
       std::string cmd = action + ' ' + file_or_dir;