[glibmm] Replace ScopedPtr with make_unique_ptr_gfree().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Replace ScopedPtr with make_unique_ptr_gfree().
- Date: Mon, 18 Jan 2016 10:14:59 +0000 (UTC)
commit 931fccd08c793f1ed44013663f8a52835a328831
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jan 18 11:14:02 2016 +0100
Replace ScopedPtr with make_unique_ptr_gfree().
Using std::unique_ptr. ScopedPtr is now deprecated.
Bug #760223
glib/glibmm/base64.cc | 4 +-
glib/glibmm/stringutils.cc | 6 ++--
glib/glibmm/ustring.cc | 46 ++++++++++++++++++++++---------------------
glib/glibmm/utility.h | 25 ++++++++++++++++++++---
glib/src/convert.ccg | 33 +++++++++++++++++--------------
glib/src/date.ccg | 2 +-
glib/src/fileutils.ccg | 20 +++++++++---------
glib/src/iochannel.ccg | 16 +++++++-------
glib/src/keyfile.ccg | 4 +-
glib/src/markup.ccg | 2 +-
glib/src/regex.ccg | 2 +-
glib/src/shell.ccg | 4 +-
glib/src/spawn.ccg | 32 ++++++++++++++++++------------
13 files changed, 112 insertions(+), 84 deletions(-)
---
diff --git a/glib/glibmm/base64.cc b/glib/glibmm/base64.cc
index 31d913c..ba951e3 100644
--- a/glib/glibmm/base64.cc
+++ b/glib/glibmm/base64.cc
@@ -32,7 +32,7 @@ std::string Base64::encode(const std::string& source, bool break_lines)
*/
gsize length = (source.length() / 3 + 1) * 4 + 1; // + 1 for the terminating zero
length += ((length / 72) + 1); // in case break_lines = true
- const Glib::ScopedPtr<char> buf ((char*) g_malloc(length));
+ const auto buf = make_unique_ptr_gfree((char*) g_malloc(length));
gint state = 0, save = 0;
const guchar* src = reinterpret_cast<const unsigned char*>(source.data());
gsize out = g_base64_encode_step (src, source.length(), break_lines,
@@ -44,7 +44,7 @@ std::string Base64::encode(const std::string& source, bool break_lines)
std::string Base64::decode(const std::string& source)
{
gsize size;
- const Glib::ScopedPtr<char> buf((char*)g_base64_decode(source.c_str(), &size));
+ const auto buf = make_unique_ptr_gfree((char*)g_base64_decode(source.c_str(), &size));
return std::string(buf.get(), buf.get() + size);
}
diff --git a/glib/glibmm/stringutils.cc b/glib/glibmm/stringutils.cc
index ee13973..5eb58c1 100644
--- a/glib/glibmm/stringutils.cc
+++ b/glib/glibmm/stringutils.cc
@@ -87,19 +87,19 @@ std::string Glib::Ascii::dtostr(double d)
std::string Glib::strescape(const std::string& source)
{
- const Glib::ScopedPtr<char> buf (g_strescape(source.c_str(), nullptr));
+ const auto buf = make_unique_ptr_gfree(g_strescape(source.c_str(), nullptr));
return buf.get();
}
std::string Glib::strescape(const std::string& source, const std::string& exceptions)
{
- const Glib::ScopedPtr<char> buf (g_strescape(source.c_str(), exceptions.c_str()));
+ const auto buf = make_unique_ptr_gfree(g_strescape(source.c_str(), exceptions.c_str()));
return buf.get();
}
std::string Glib::strcompress(const std::string& source)
{
- const Glib::ScopedPtr<char> buf (g_strcompress(source.c_str()));
+ const auto buf = make_unique_ptr_gfree(g_strcompress(source.c_str()));
return buf.get();
}
diff --git a/glib/glibmm/ustring.cc b/glib/glibmm/ustring.cc
index 78b0e5b..dc89875 100644
--- a/glib/glibmm/ustring.cc
+++ b/glib/glibmm/ustring.cc
@@ -149,8 +149,9 @@ ustring::size_type utf8_find_first_of(const std::string& str, ustring::size_type
return ustring::npos;
long ucs4_match_size = 0;
- const Glib::ScopedPtr<gunichar> ucs4_match
- (g_utf8_to_ucs4_fast(utf8_match, utf8_match_size, &ucs4_match_size));
+ const auto ucs4_match =
+ Glib::make_unique_ptr_gfree(
+ g_utf8_to_ucs4_fast(utf8_match, utf8_match_size, &ucs4_match_size));
const gunichar *const match_begin = ucs4_match.get();
const gunichar *const match_end = match_begin + ucs4_match_size;
@@ -181,8 +182,9 @@ ustring::size_type utf8_find_last_of(const std::string& str, ustring::size_type
bool find_not_of)
{
long ucs4_match_size = 0;
- const Glib::ScopedPtr<gunichar> ucs4_match
- (g_utf8_to_ucs4_fast(utf8_match, utf8_match_size, &ucs4_match_size));
+ const auto ucs4_match =
+ Glib::make_unique_ptr_gfree(
+ g_utf8_to_ucs4_fast(utf8_match, utf8_match_size, &ucs4_match_size));
const gunichar *const match_begin = ucs4_match.get();
const gunichar *const match_end = match_begin + ucs4_match_size;
@@ -1170,32 +1172,32 @@ bool ustring::is_ascii() const
ustring ustring::normalize(NormalizeMode mode) const
{
- const ScopedPtr<char> buf (g_utf8_normalize(string_.data(), string_.size(),
+ const auto buf = make_unique_ptr_gfree(g_utf8_normalize(string_.data(), string_.size(),
static_cast<GNormalizeMode>(int(mode))));
return ustring(buf.get());
}
ustring ustring::uppercase() const
{
- const ScopedPtr<char> buf (g_utf8_strup(string_.data(), string_.size()));
+ const auto buf = make_unique_ptr_gfree(g_utf8_strup(string_.data(), string_.size()));
return ustring(buf.get());
}
ustring ustring::lowercase() const
{
- const ScopedPtr<char> buf (g_utf8_strdown(string_.data(), string_.size()));
+ const auto buf = make_unique_ptr_gfree(g_utf8_strdown(string_.data(), string_.size()));
return ustring(buf.get());
}
ustring ustring::casefold() const
{
- const ScopedPtr<char> buf (g_utf8_casefold(string_.data(), string_.size()));
+ const auto buf = make_unique_ptr_gfree(g_utf8_casefold(string_.data(), string_.size()));
return ustring(buf.get());
}
std::string ustring::collate_key() const
{
- const ScopedPtr<char> buf (g_utf8_collate_key(string_.data(), string_.size()));
+ const auto buf = make_unique_ptr_gfree(g_utf8_collate_key(string_.data(), string_.size()));
return std::string(buf.get());
}
@@ -1204,7 +1206,7 @@ std::string ustring::casefold_collate_key() const
char *const casefold_buf = g_utf8_casefold(string_.data(), string_.size());
char *const key_buf = g_utf8_collate_key(casefold_buf, -1);
g_free(casefold_buf);
- return std::string(ScopedPtr<char>(key_buf).get());
+ return std::string(make_unique_ptr_gfree(key_buf).get());
}
/**** Glib::ustring -- Message formatting **********************************/
@@ -1294,16 +1296,16 @@ ustring ustring::FormatStream::to_string() const
# if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
// Avoid going through iconv if wchar_t always contains UCS-4.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_ucs4_to_utf8(reinterpret_cast<const gunichar*>(str.data()),
+ const auto buf = make_unique_ptr_gfree(g_ucs4_to_utf8(reinterpret_cast<const gunichar*>(str.data()),
str.size(), nullptr, &n_bytes, &error));
# elif defined(G_OS_WIN32) && SIZEOF_WCHAR_T == 2
// Avoid going through iconv if wchar_t always contains UTF-16.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(str.data()),
+ const auto buf = make_unique_ptr_gfree(g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(str.data()),
str.size(), nullptr, &n_bytes, &error));
# else
gsize n_bytes = 0;
- const ScopedPtr<char> buf (g_convert(reinterpret_cast<const char*>(str.data()),
+ const auto buf = make_unique_ptr_gfree(g_convert(reinterpret_cast<const char*>(str.data()),
str.size() * sizeof(std::wstring::value_type),
"UTF-8", "WCHAR_T", nullptr, &n_bytes, &error));
# endif /* !(__STDC_ISO_10646__ || G_OS_WIN32) */
@@ -1312,7 +1314,7 @@ ustring ustring::FormatStream::to_string() const
const std::string str = stream_.str();
gsize n_bytes = 0;
- const ScopedPtr<char> buf (g_locale_to_utf8(str.data(), str.size(), 0, &n_bytes, &error));
+ const auto buf = make_unique_ptr_gfree(g_locale_to_utf8(str.data(), str.size(), 0, &n_bytes, &error));
#endif /* !GLIBMM_HAVE_WIDE_STREAM */
if (error)
@@ -1332,7 +1334,7 @@ std::istream& operator>>(std::istream& is, Glib::ustring& utf8_string)
GError* error = nullptr;
gsize n_bytes = 0;
- const ScopedPtr<char> buf (g_locale_to_utf8(str.data(), str.size(), nullptr, &n_bytes, &error));
+ const auto buf = make_unique_ptr_gfree(g_locale_to_utf8(str.data(), str.size(), nullptr, &n_bytes,
&error));
if (error)
{
@@ -1347,7 +1349,7 @@ std::istream& operator>>(std::istream& is, Glib::ustring& utf8_string)
std::ostream& operator<<(std::ostream& os, const Glib::ustring& utf8_string)
{
GError* error = nullptr;
- const ScopedPtr<char> buf (g_locale_from_utf8(utf8_string.raw().data(),
+ const auto buf = make_unique_ptr_gfree(g_locale_from_utf8(utf8_string.raw().data(),
utf8_string.raw().size(), nullptr, nullptr, &error));
if (error)
{
@@ -1378,16 +1380,16 @@ std::wistream& operator>>(std::wistream& is, ustring& utf8_string)
#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
// Avoid going through iconv if wchar_t always contains UCS-4.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_ucs4_to_utf8(reinterpret_cast<const gunichar*>(wstr.data()),
+ const auto buf = make_unique_ptr_gfree(g_ucs4_to_utf8(reinterpret_cast<const gunichar*>(wstr.data()),
wstr.size(), nullptr, &n_bytes, &error));
#elif defined(G_OS_WIN32) && SIZEOF_WCHAR_T == 2
// Avoid going through iconv if wchar_t always contains UTF-16.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(wstr.data()),
+ const auto buf = make_unique_ptr_gfree(g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(wstr.data()),
wstr.size(), nullptr, &n_bytes, &error));
#else
gsize n_bytes = 0;
- const ScopedPtr<char> buf (g_convert(reinterpret_cast<const char*>(wstr.data()),
+ const auto buf = make_unique_ptr_gfree(g_convert(reinterpret_cast<const char*>(wstr.data()),
wstr.size() * sizeof(std::wstring::value_type),
"UTF-8", "WCHAR_T", nullptr, &n_bytes, &error));
#endif // !(__STDC_ISO_10646__ || G_OS_WIN32)
@@ -1408,14 +1410,14 @@ std::wostream& operator<<(std::wostream& os, const ustring& utf8_string)
#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
// Avoid going through iconv if wchar_t always contains UCS-4.
- const ScopedPtr<gunichar> buf (g_utf8_to_ucs4(utf8_string.raw().data(),
+ const auto buf = make_unique_ptr_gfree(g_utf8_to_ucs4(utf8_string.raw().data(),
utf8_string.raw().size(), nullptr, nullptr, &error));
#elif defined(G_OS_WIN32) && SIZEOF_WCHAR_T == 2
// Avoid going through iconv if wchar_t always contains UTF-16.
- const ScopedPtr<gunichar2> buf (g_utf8_to_utf16(utf8_string.raw().data(),
+ const auto buf = make_unique_ptr_gfree(g_utf8_to_utf16(utf8_string.raw().data(),
utf8_string.raw().size(), nullptr, nullptr, &error));
#else
- const ScopedPtr<char> buf (g_convert(utf8_string.raw().data(), utf8_string.raw().size(),
+ const auto buf = make_unique_ptr_gfree(g_convert(utf8_string.raw().data(), utf8_string.raw().size(),
"WCHAR_T", "UTF-8", nullptr, nullptr, &error));
#endif // !(__STDC_ISO_10646__ || G_OS_WIN32)
diff --git a/glib/glibmm/utility.h b/glib/glibmm/utility.h
index 379b524..d49947c 100644
--- a/glib/glibmm/utility.h
+++ b/glib/glibmm/utility.h
@@ -21,6 +21,7 @@
#include <glibmmconfig.h>
#include <glibmm/ustring.h>
#include <glib.h>
+#include <memory> //For std::unique_ptr.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -57,9 +58,13 @@ namespace Glib
// These are used by gtkmmproc-generated type conversions:
+#ifdef GLIBMM_DISABLE_DEPRECATED
// TODO: Replace this with std::unique_ptr?
-// Helper to deal with memory allocated
-// by GLib functions in an exception-safe manner.
+/** Helper to deal with memory allocated
+ * by GLib functions in an exception-safe manner.
+ *
+ * @deprecated Use UniquePtrGFree instead.
+ */
template <typename T>
class ScopedPtr
{
@@ -75,6 +80,18 @@ public:
T* get() const { return ptr_; }
T** addr() { return &ptr_; }
};
+#endif //GLIBMM_DISABLE_DEPRECATED
+
+/** Helper to deal with memory allocated
+ * by GLib functions in an exception-safe manner.
+ *
+ * This just creates a unique_ptr that uses g_free as its deleter.
+ */
+template <typename T>
+std::unique_ptr<T[], decltype(&g_free)> make_unique_ptr_gfree(T* p)
+{
+ return std::unique_ptr<T[], decltype(&g_free)>(p, &g_free);
+}
//TODO: Deprecate this? We don't use it ourselves.
/** Removes the const nature of a ptr
@@ -102,7 +119,7 @@ std::string convert_const_gchar_ptr_to_stdstring(const char* str)
inline
Glib::ustring convert_return_gchar_ptr_to_ustring(char* str)
{
- return (str) ? Glib::ustring(Glib::ScopedPtr<char>(str).get())
+ return (str) ? Glib::ustring(Glib::make_unique_ptr_gfree(str).get())
: Glib::ustring();
}
@@ -110,7 +127,7 @@ Glib::ustring convert_return_gchar_ptr_to_ustring(char* str)
inline
std::string convert_return_gchar_ptr_to_stdstring(char* str)
{
- return (str) ? std::string(Glib::ScopedPtr<char>(str).get())
+ return (str) ? std::string(Glib::make_unique_ptr_gfree(str).get())
: std::string();
}
diff --git a/glib/src/convert.ccg b/glib/src/convert.ccg
index 4204c24..cc17285 100644
--- a/glib/src/convert.ccg
+++ b/glib/src/convert.ccg
@@ -87,7 +87,8 @@ std::string IConv::convert(const std::string& str)
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get(), bytes_written);
+ //TODO: Avoid the copy by using a perfect-forwarding std::string constructor?
+ return std::string(make_unique_ptr_gfree(buf).get(), bytes_written);
}
@@ -121,7 +122,8 @@ std::string convert(const std::string& str,
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get(), bytes_written);
+ //TODO: Avoid the copy by using a perfect-forwarding std::string constructor?
+ return std::string(make_unique_ptr_gfree(buf).get(), bytes_written);
}
@@ -138,7 +140,8 @@ std::string convert_with_fallback(const std::string& str,
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get(), bytes_written);
+ //TODO: Avoid the copy by using a perfect-forwarding std::string constructor?
+ return std::string(make_unique_ptr_gfree(buf).get(), bytes_written);
}
@@ -156,7 +159,7 @@ std::string convert_with_fallback(const std::string& str,
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get(), bytes_written);
+ return std::string(make_unique_ptr_gfree(buf).get(), bytes_written);
}
@@ -170,7 +173,7 @@ Glib::ustring locale_to_utf8(const std::string& opsys_string)
if(gerror) ::Glib::Error::throw_exception(gerror);
- const ScopedPtr<char> scoped_buf (buf);
+ const auto scoped_buf = make_unique_ptr_gfree(buf));
return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written);
}
@@ -185,7 +188,7 @@ std::string locale_from_utf8(const Glib::ustring& utf8_string)
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get(), bytes_written);
+ return std::string(make_unique_ptr_gfree(buf).get(), bytes_written);
}
@@ -199,7 +202,7 @@ Glib::ustring filename_to_utf8(const std::string& opsys_string)
if(gerror) ::Glib::Error::throw_exception(gerror);
- const ScopedPtr<char> scoped_buf (buf);
+ const auto scoped_buf = make_unique_ptr_gfree(buf);
return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written);
}
@@ -214,7 +217,7 @@ std::string filename_from_utf8(const Glib::ustring& utf8_string)
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get(), bytes_written);
+ return std::string(make_unique_ptr_gfree(buf).get(), bytes_written);
}
@@ -228,10 +231,10 @@ std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname)
if(gerror) ::Glib::Error::throw_exception(gerror);
// Let's take ownership at this point.
- const ScopedPtr<char> scoped_buf (buf);
+ const auto scoped_buf = make_unique_ptr_gfree(buf));
if(hostname_buf)
- hostname = ScopedPtr<char>(hostname_buf).get();
+ hostname = make_unique_ptr_gfree(buf).get();
else
hostname.erase();
@@ -246,7 +249,7 @@ std::string filename_from_uri(const Glib::ustring& uri)
if(gerror) ::Glib::Error::throw_exception(gerror);
- return std::string(ScopedPtr<char>(buf).get());
+ return std::string(make_unique_ptr_gfree(buf).get());
}
@@ -257,7 +260,7 @@ Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring&
if(gerror) ::Glib::Error::throw_exception(gerror);
- return Glib::ustring(ScopedPtr<char>(buf).get());
+ return Glib::ustring(make_unique_ptr_gfree(buf).get());
}
@@ -268,14 +271,14 @@ Glib::ustring filename_to_uri(const std::string& filename)
if(gerror) ::Glib::Error::throw_exception(gerror);
- return Glib::ustring(ScopedPtr<char>(buf).get());
+ return Glib::ustring(make_unique_ptr_gfree(buf).get());
}
Glib::ustring filename_display_basename(const std::string& filename)
{
char *const buf = g_filename_display_basename(filename.c_str());
- return Glib::ustring(ScopedPtr<char>(buf).get());
+ return Glib::ustring(make_unique_ptr_gfree(buf).get());
}
@@ -283,7 +286,7 @@ Glib::ustring filename_display_name(const std::string& filename)
{
char *const buf = g_filename_display_name(filename.c_str());
- return Glib::ustring(ScopedPtr<char>(buf).get());
+ return Glib::ustring(make_unique_ptr_gfree(buf).get());
}
} // namespace Glib
diff --git a/glib/src/date.ccg b/glib/src/date.ccg
index bd65cd4..4dcc3f4 100644
--- a/glib/src/date.ccg
+++ b/glib/src/date.ccg
@@ -311,7 +311,7 @@ Glib::ustring Date::format_string(const Glib::ustring& format) const
do
{
- const ScopedPtr<char> buf (static_cast<char*>(g_malloc(bufsize)));
+ const auto buf = make_unique_ptr_gfree(static_cast<char*>(g_malloc(bufsize)));
// Set the first byte to something other than '\0', to be able to
// recognize whether strftime actually failed or just returned "".
diff --git a/glib/src/fileutils.ccg b/glib/src/fileutils.ccg
index 6fb7f56..36385f6 100644
--- a/glib/src/fileutils.ccg
+++ b/glib/src/fileutils.ccg
@@ -124,7 +124,7 @@ bool file_test(const std::string& filename, FileTest test)
int mkstemp(std::string& filename_template)
{
- const ScopedPtr<char> buf (g_strndup(filename_template.data(), filename_template.size()));
+ const auto buf = make_unique_ptr_gfree(g_strndup(filename_template.data(), filename_template.size()));
const auto fileno = g_mkstemp(buf.get());
filename_template = buf.get();
@@ -137,10 +137,10 @@ int file_open_tmp(std::string& name_used, const std::string& prefix)
basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface
GError* error = nullptr;
- ScopedPtr<char> buf_name_used;
-
- const auto fileno = g_file_open_tmp(basename_template.c_str(), buf_name_used.addr(), &error);
+ char* pch_buf_name_used = nullptr;
+ const auto fileno = g_file_open_tmp(basename_template.c_str(), &pch_buf_name_used, &error);
+ auto buf_name_used = make_unique_ptr_gfree(pch_buf_name_used);
if(error)
Glib::Error::throw_exception(error);
@@ -151,10 +151,10 @@ int file_open_tmp(std::string& name_used, const std::string& prefix)
int file_open_tmp(std::string& name_used)
{
GError* error = nullptr;
- ScopedPtr<char> buf_name_used;
-
- const auto fileno = g_file_open_tmp(nullptr, buf_name_used.addr(), &error);
+ char* pch_buf_name_used = nullptr;
+ const auto fileno = g_file_open_tmp(nullptr, &pch_buf_name_used, &error);
+ auto buf_name_used = make_unique_ptr_gfree(pch_buf_name_used);
if(error)
Glib::Error::throw_exception(error);
@@ -164,12 +164,12 @@ int file_open_tmp(std::string& name_used)
std::string file_get_contents(const std::string& filename)
{
- ScopedPtr<char> contents;
gsize length = 0;
GError* error = nullptr;
- g_file_get_contents(filename.c_str(), contents.addr(), &length, &error);
-
+ char* pch_contents = nullptr;
+ g_file_get_contents(filename.c_str(), &pch_contents, &length, &error);
+ auto contents = make_unique_ptr_gfree(pch_contents);
if(error)
Glib::Error::throw_exception(error);
diff --git a/glib/src/iochannel.ccg b/glib/src/iochannel.ccg
index 81b1eb2..c1d88e4 100644
--- a/glib/src/iochannel.ccg
+++ b/glib/src/iochannel.ccg
@@ -231,12 +231,12 @@ IOStatus IOChannel::write(const Glib::ustring& str)
IOStatus IOChannel::read_line(Glib::ustring& line)
{
- Glib::ScopedPtr<char> buf;
GError* gerror = nullptr;
gsize bytes = 0;
+ char* pch_buf = nullptr;
- const auto status = g_io_channel_read_line(gobj(), buf.addr(), &bytes, nullptr, &gerror);
-
+ const auto status = g_io_channel_read_line(gobj(), &pch_buf, &bytes, nullptr, &gerror);
+ auto buf = make_unique_ptr_gfree(pch_buf);
if(gerror)
{
Glib::Error::throw_exception(gerror);
@@ -252,12 +252,12 @@ IOStatus IOChannel::read_line(Glib::ustring& line)
IOStatus IOChannel::read_to_end(Glib::ustring& str)
{
- Glib::ScopedPtr<char> buf;
GError* gerror = nullptr;
gsize bytes = 0;
+ char* pch_buf = nullptr;
- const auto status = g_io_channel_read_to_end(gobj(), buf.addr(), &bytes, &gerror);
-
+ const auto status = g_io_channel_read_to_end(gobj(), &pch_buf, &bytes, &gerror);
+ auto buf = make_unique_ptr_gfree(pch_buf);
if(gerror)
{
Glib::Error::throw_exception(gerror);
@@ -273,13 +273,13 @@ IOStatus IOChannel::read_to_end(Glib::ustring& str)
IOStatus IOChannel::read(Glib::ustring& str, gsize count)
{
- Glib::ScopedPtr<char> buf (g_new(char, count));
+ Glib::UniquePtrGFree<char> buf (g_new(char, count));
GError* gerror = nullptr;
gsize bytes = 0;
const auto status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &gerror);
- if(gerror)
+ if(gerror)
{
Glib::Error::throw_exception(gerror);
}
diff --git a/glib/src/keyfile.ccg b/glib/src/keyfile.ccg
index 71c94a5..7292d2e 100644
--- a/glib/src/keyfile.ccg
+++ b/glib/src/keyfile.ccg
@@ -89,7 +89,7 @@ bool KeyFile::load_from_data_dirs(const std::string& file, std::string& full_pat
Glib::Error::throw_exception(gerror);
if(full_path_c)
- full_path = Glib::ScopedPtr<char>(full_path_c).get();
+ full_path = Glib::make_unique_ptr_gfree(buf).get();
else
full_path.erase();
@@ -116,7 +116,7 @@ bool KeyFile::load_from_dirs(const std::string& file, const Glib::ArrayHandle<st
}
if(full_path_c)
- full_path = Glib::ScopedPtr<char>(full_path_c).get();
+ full_path = Glib::make_unique_ptr_gfree(buf).get();
else
full_path.erase();
diff --git a/glib/src/markup.ccg b/glib/src/markup.ccg
index d3ae62b..246510f 100644
--- a/glib/src/markup.ccg
+++ b/glib/src/markup.ccg
@@ -29,7 +29,7 @@ namespace Markup
Glib::ustring escape_text(const Glib::ustring& text)
{
- const Glib::ScopedPtr<char> buf (g_markup_escape_text(text.data(), text.bytes()));
+ const Glib::UniquePtrGFree<char> buf (g_markup_escape_text(text.data(), text.bytes()));
return Glib::ustring(buf.get());
}
diff --git a/glib/src/regex.ccg b/glib/src/regex.ccg
index 1ee7299..0ffe5f7 100644
--- a/glib/src/regex.ccg
+++ b/glib/src/regex.ccg
@@ -36,7 +36,7 @@ Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern,
// static
Glib::ustring Regex::escape_string(const Glib::ustring& string)
{
- const Glib::ScopedPtr<char> buf (g_regex_escape_string(string.raw().c_str(),
+ const Glib::UniquePtrGFree<char> buf (g_regex_escape_string(string.raw().c_str(),
string.raw().size()));
return Glib::ustring(buf.get());
}
diff --git a/glib/src/shell.ccg b/glib/src/shell.ccg
index db01f78..84b9a51 100644
--- a/glib/src/shell.ccg
+++ b/glib/src/shell.ccg
@@ -39,7 +39,7 @@ Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line)
std::string shell_quote(const std::string& unquoted_string)
{
- const ScopedPtr<char> buf (g_shell_quote(unquoted_string.c_str()));
+ const auto buf = make_unique_ptr_gfree(g_shell_quote(unquoted_string.c_str()));
return std::string(buf.get());
}
@@ -51,7 +51,7 @@ std::string shell_unquote(const std::string& quoted_string)
if(error)
Glib::Error::throw_exception(error);
- return std::string(ScopedPtr<char>(buf).get());
+ return std::string(make_unique_ptr_gfree(buf).get());
}
} // namespace Glib
diff --git a/glib/src/spawn.ccg b/glib/src/spawn.ccg
index 703236e..738203c 100644
--- a/glib/src/spawn.ccg
+++ b/glib/src/spawn.ccg
@@ -179,10 +179,10 @@ void spawn_sync(const std::string& working_directory,
const bool setup_slot = !child_setup.empty();
auto child_setup_ = child_setup;
- Glib::ScopedPtr<char> buf_standard_output;
- Glib::ScopedPtr<char> buf_standard_error;
- GError* gerror = nullptr;
+ GError* gerror = nullptr;
+ char* pch_buf_standard_output = nullptr;
+ char* pch_buf_standard_error = nullptr;
g_spawn_sync(
(working_directory.empty()) ? nullptr : working_directory.c_str(),
const_cast<char**>(argv.data()),
@@ -190,10 +190,12 @@ void spawn_sync(const std::string& working_directory,
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : nullptr,
(setup_slot) ? &child_setup_ : nullptr,
- (standard_output) ? buf_standard_output.addr() : nullptr,
- (standard_error) ? buf_standard_error.addr() : nullptr,
+ (standard_output) ? &pch_buf_standard_output : nullptr,
+ (standard_error) ? &pch_buf_standard_error : nullptr,
exit_status,
&gerror);
+ auto buf_standard_output = make_unique_ptr_gfree(pch_buf_standard_output);
+ auto buf_standard_error = make_unique_ptr_gfree(pch_buf_standard_error);
if(gerror)
Glib::Error::throw_exception(gerror);
@@ -213,8 +215,8 @@ void spawn_sync(const std::string& working_directory,
const bool setup_slot = !child_setup.empty();
auto child_setup_ = child_setup;
- Glib::ScopedPtr<char> buf_standard_output;
- Glib::ScopedPtr<char> buf_standard_error;
+ char* pch_buf_standard_output = nullptr;
+ char* pch_buf_standard_error = nullptr;
GError* gerror = nullptr;
g_spawn_sync(
@@ -223,10 +225,12 @@ void spawn_sync(const std::string& working_directory,
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : nullptr,
(setup_slot) ? &child_setup_ : nullptr,
- (standard_output) ? buf_standard_output.addr() : nullptr,
- (standard_error) ? buf_standard_error.addr() : nullptr,
+ (standard_output) ? &pch_buf_standard_output : nullptr,
+ (standard_error) ? &pch_buf_standard_error : nullptr,
exit_status,
&gerror);
+ auto buf_standard_output = make_unique_ptr_gfree(pch_buf_standard_output);
+ auto buf_standard_error = make_unique_ptr_gfree(pch_buf_standard_error);
if(gerror)
Glib::Error::throw_exception(gerror);
@@ -249,16 +253,18 @@ void spawn_command_line_sync(const std::string& command_line,
std::string* standard_error,
int* exit_status)
{
- Glib::ScopedPtr<char> buf_standard_output;
- Glib::ScopedPtr<char> buf_standard_error;
+ char* pch_buf_standard_output = nullptr;
+ char* pch_buf_standard_error = nullptr;
GError* gerror = nullptr;
g_spawn_command_line_sync(
command_line.c_str(),
- (standard_output) ? buf_standard_output.addr() : nullptr,
- (standard_error) ? buf_standard_error.addr() : nullptr,
+ (standard_output) ? &pch_buf_standard_output : nullptr,
+ (standard_error) ? &pch_buf_standard_error : nullptr,
exit_status,
&gerror);
+ auto buf_standard_output = make_unique_ptr_gfree(pch_buf_standard_output);
+ auto buf_standard_error = make_unique_ptr_gfree(pch_buf_standard_error);
if(gerror)
Glib::Error::throw_exception(gerror);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]