[vte] widget: Use safe getter
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Use safe getter
- Date: Thu, 22 Oct 2020 18:35:03 +0000 (UTC)
commit a1fbb9df57492c4d3c298099f0a242261be7ccc3
Author: Christian Persch <chpe src gnome org>
Date: Thu Oct 22 20:34:52 2020 +0200
widget: Use safe getter
src/glib-glue.hh | 2 ++
src/widget.cc | 16 +++++++---------
2 files changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/src/glib-glue.hh b/src/glib-glue.hh
index d075817d..ab620338 100644
--- a/src/glib-glue.hh
+++ b/src/glib-glue.hh
@@ -40,6 +40,7 @@ take_free_ptr(T* ptr)
}
using StringPtr = FreePtr<char>;
+using StringGetter = vte::ValueGetter<StringPtr, char*, nullptr>;
inline StringPtr
take_string(char* str)
@@ -54,6 +55,7 @@ dup_string(char const* str)
}
using StrvPtr = vte::FreeablePtr<char*, decltype(&g_strfreev), &g_strfreev>;
+using StrvGetter = vte::ValueGetter<StrvPtr, char**, nullptr>;
inline StrvPtr
take_strv(char** strv)
diff --git a/src/widget.cc b/src/widget.cc
index 31061413..c774ec29 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -348,20 +348,18 @@ Widget::im_focus_out() noexcept
void
Widget::im_preedit_changed() noexcept
{
- char* str = nullptr;
- int cursorpos = 0;
-
+ auto str = vte::glib::StringPtr{};
auto attrs = vte::Freeable<PangoAttrList>{};
- gtk_im_context_get_preedit_string(m_im_context.get(), &str,
+ auto cursorpos = 0;
+ gtk_im_context_get_preedit_string(m_im_context.get(),
+ vte::glib::StringGetter{str},
vte::get_freeable(attrs),
&cursorpos);
_vte_debug_print(VTE_DEBUG_EVENTS, "Input method pre-edit changed (%s,%d).\n",
- str, cursorpos);
-
- if (str != nullptr)
- m_terminal->im_preedit_changed(str, cursorpos, std::move(attrs));
+ str.get(), cursorpos);
- g_free(str);
+ if (str)
+ m_terminal->im_preedit_changed(str.get(), cursorpos, std::move(attrs));
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]