[gjs: 4/12] maint: Use GjsAutoPointer out() method
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 4/12] maint: Use GjsAutoPointer out() method
- Date: Tue, 10 Aug 2021 04:08:01 +0000 (UTC)
commit 82cd39394fc4d07790482b2b823d92dc1497cc8c
Author: Philip Chimento <philip chimento gmail com>
Date: Thu Jul 8 22:02:55 2021 -0700
maint: Use GjsAutoPointer out() method
We had a few instances of the pattern where we pass a pointer to a GLib
function as an out argument, and then assign the pointer to a GjsAutoChar.
This is no longer necessary now that we have the GjsAutoChar::out()
method, and can be done more cleanly.
gjs/importer.cpp | 8 +++-----
gjs/internal.cpp | 5 ++---
gjs/jsapi-util.cpp | 6 ++----
3 files changed, 7 insertions(+), 12 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 1d41a7e2..f8830a7c 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -303,9 +303,9 @@ import_module_init(JSContext *context,
GjsContextPrivate* gjs = GjsContextPrivate::from_cx(context);
JS::RootedValue ignored(context);
- char* script_unowned;
- if (!(g_file_load_contents(file, nullptr, &script_unowned, &script_len,
- nullptr, &error))) {
+ GjsAutoChar script;
+ if (!g_file_load_contents(file, nullptr, script.out(), &script_len, nullptr,
+ &error)) {
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY) &&
!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY) &&
!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
@@ -315,8 +315,6 @@ import_module_init(JSContext *context,
return false;
}
-
- GjsAutoChar script = script_unowned;
g_assert(script);
GjsAutoChar full_path = g_file_get_parse_name(file);
diff --git a/gjs/internal.cpp b/gjs/internal.cpp
index 845f2641..ed856ac4 100644
--- a/gjs/internal.cpp
+++ b/gjs/internal.cpp
@@ -70,12 +70,11 @@ bool gjs_load_internal_module(JSContext* cx, const char* identifier) {
gjs_debug(GJS_DEBUG_IMPORTER, "Loading internal module '%s' (%s)",
identifier, full_path.get());
- char* script_unowned;
+ GjsAutoChar script;
size_t script_len;
- if (!gjs_load_internal_source(cx, full_path, &script_unowned, &script_len))
+ if (!gjs_load_internal_source(cx, full_path, script.out(), &script_len))
return false;
- GjsAutoChar script = script_unowned;
JS::SourceText<mozilla::Utf8Unit> buf;
if (!buf.init(cx, script.get(), script_len, JS::SourceOwnership::Borrowed))
return false;
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index f987a530..6f2df2cd 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -517,12 +517,10 @@ static void _linux_get_self_process_size(long* rss_size) // NOLINT(runtime/int)
*rss_size = 0;
- char* contents_unowned;
- if (!g_file_get_contents("/proc/self/stat", &contents_unowned, &len,
- nullptr))
+ GjsAutoChar contents;
+ if (!g_file_get_contents("/proc/self/stat", contents.out(), &len, nullptr))
return;
- GjsAutoChar contents = contents_unowned;
iter = contents;
// See "man proc" for where this 23 comes from
for (i = 0; i < 23; i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]