Mercurial > octave
diff liboctave/util/oct-string.cc @ 28824:a98fd0657e35
Replace unwind_protect with more efficient constructs in liboctave (bug #59192).
* lo-sysdep.cc, oct-glob.cc, oct-string.cc, url-transfer.cc:
Replace frame.add_fcn () instances with unwind_action<> object.
* unwind-prot.h (unwind_action): Add note to documentation that function
pointer or lambda expression are possible inputs.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 30 Sep 2020 04:16:37 -0700 |
parents | c20b7290c778 |
children | 445e5ac1f58d |
line wrap: on
line diff
--- a/liboctave/util/oct-string.cc Wed Sep 30 03:17:52 2020 -0700 +++ b/liboctave/util/oct-string.cc Wed Sep 30 04:16:37 2020 -0700 @@ -516,8 +516,11 @@ who.c_str (), encoding.c_str (), std::strerror (errno)); } - octave::unwind_protect frame; - frame.add_fcn (::free, static_cast<void *> (native_str)); + octave::unwind_action free_native_str + ([] (const auto native_str_ptr) + { + ::free (native_str_ptr); + }, static_cast<void *> (native_str)); std::string retval = std::string (native_str, length); @@ -547,8 +550,11 @@ who.c_str (), encoding.c_str (), std::strerror (errno)); } - octave::unwind_protect frame; - frame.add_fcn (::free, static_cast<void *> (utf8_str)); + octave::unwind_action free_utf8_str + ([] (const auto utf8_str_ptr) + { + ::free (utf8_str_ptr); + }, static_cast<void *> (utf8_str)); std::string retval = std::string (reinterpret_cast<char *> (utf8_str), length); @@ -594,8 +600,11 @@ ("%s: converting from codepage '%s' to UTF-8 failed: %s", who.c_str (), fallback.c_str (), std::strerror (errno)); - octave::unwind_protect frame; - frame.add_fcn (::free, static_cast<void *> (val_utf8)); + octave::unwind_action free_val_utf8 + ([] (const auto val_utf8_ptr) + { + ::free (val_utf8_ptr); + }, static_cast<void *> (val_utf8)); out_str.append (reinterpret_cast<const char *> (val_utf8), lengthp);