summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2020-09-02 17:17:07 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2020-09-04 00:53:18 +0200
commite54ba8eb11bb652e2b9b4126dacc5ccad4752dbb (patch)
treee1dc949586097b86e883a9285a361c5529ffbe11
parentd4356e0dc549c472e304ae5a525c59f30d588f9c (diff)
downloadgjs-e54ba8eb11bb652e2b9b4126dacc5ccad4752dbb.tar.gz
cleanup: Don't use GSlice anywhere
GSlice API is going to be deprecated [1] and marked as such for some years now, even if this change didn't happen yet, there's no point to keep GSlice usage in gjs, considering that we can semplificate it with calls to system allocator using g_new/g_malloc and g_free. Once I applied this change, I've noticed that the memory sanitzer found some leaks in the trampoline code that for some reason GSlice was hiding and that this commit underlines. [1] https://gitlab.gnome.org/GNOME/glib/-/issues/1079
-rw-r--r--gi/arg-cache.cpp13
-rw-r--r--gi/boxed.cpp4
-rw-r--r--gi/function.cpp8
-rw-r--r--gi/ns.cpp4
-rw-r--r--gi/repo.cpp4
-rw-r--r--gi/wrapperutils.h4
-rw-r--r--gjs/importer.cpp4
7 files changed, 21 insertions, 20 deletions
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 7f75a8b4..92121ce8 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -362,7 +362,7 @@ GJS_JSAPI_RETURN_CONVENTION
static bool gjs_marshal_caller_allocates_in(JSContext*, GjsArgumentCache* self,
GjsFunctionCallState* state,
GIArgument* arg, JS::HandleValue) {
- void* blob = g_slice_alloc0(self->contents.caller_allocates_size);
+ void* blob = g_malloc0(self->contents.caller_allocates_size);
gjs_arg_set(arg, blob);
gjs_arg_set(&state->out_cvalues[self->arg_pos], blob);
return true;
@@ -890,11 +890,12 @@ static bool gjs_marshal_explicit_array_inout_release(
}
GJS_JSAPI_RETURN_CONVENTION
-static bool gjs_marshal_caller_allocates_release(
- JSContext*, GjsArgumentCache* self, GjsFunctionCallState*,
- GIArgument* in_arg, GIArgument* out_arg [[maybe_unused]]) {
- g_slice_free1(self->contents.caller_allocates_size,
- gjs_arg_get<void*>(in_arg));
+static bool gjs_marshal_caller_allocates_release(JSContext*, GjsArgumentCache*,
+ GjsFunctionCallState*,
+ GIArgument* in_arg,
+ GIArgument* out_arg
+ [[maybe_unused]]) {
+ g_free(gjs_arg_steal<void*>(in_arg));
return true;
}
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index e4b68720..140b2939 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -153,7 +153,7 @@ BoxedBase* BoxedBase::get_copy_source(JSContext* context,
void BoxedInstance::allocate_directly(void) {
g_assert(get_prototype()->can_allocate_directly());
- own_ptr(g_slice_alloc0(g_struct_info_get_size(info())));
+ own_ptr(g_malloc0(g_struct_info_get_size(info())));
m_allocated_directly = true;
debug_lifecycle("Boxed pointer directly allocated");
@@ -431,7 +431,7 @@ bool BoxedInstance::constructor_impl(JSContext* context, JS::HandleObject obj,
BoxedInstance::~BoxedInstance() {
if (m_owning_ptr) {
if (m_allocated_directly) {
- g_slice_free1(g_struct_info_get_size(info()), m_ptr);
+ g_free(m_ptr);
} else {
if (g_type_is_a(gtype(), G_TYPE_BOXED))
g_boxed_free(gtype(), m_ptr);
diff --git a/gi/function.cpp b/gi/function.cpp
index 1b065b59..97decc3c 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -107,7 +107,7 @@ gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline)
g_callable_info_free_closure(trampoline->info, trampoline->closure);
g_clear_pointer(&trampoline->info, g_base_info_unref);
g_free (trampoline->param_types);
- g_slice_free(GjsCallbackTrampoline, trampoline);
+ g_free(trampoline);
}
}
@@ -546,7 +546,7 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(
g_assert(function);
- trampoline = g_slice_new(GjsCallbackTrampoline);
+ trampoline = g_new(GjsCallbackTrampoline, 1);
new (trampoline) GjsCallbackTrampoline();
trampoline->ref_count = 1;
trampoline->info = callable_info;
@@ -1094,7 +1094,7 @@ static void function_finalize(JSFreeOp*, JSObject* obj) {
uninit_cached_function_data(priv);
GJS_DEC_COUNTER(function);
- g_slice_free(Function, priv);
+ g_free(priv);
}
GJS_JSAPI_RETURN_CONVENTION
@@ -1322,7 +1322,7 @@ function_new(JSContext *context,
return NULL;
}
- priv = g_slice_new0(Function);
+ priv = g_new0(Function, 1);
GJS_INC_COUNTER(function);
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 7cba73d5..7d62e77c 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -176,7 +176,7 @@ static void ns_finalize(JSFreeOp*, JSObject* obj) {
g_free(priv->gi_namespace);
GJS_DEC_COUNTER(ns);
- g_slice_free(Ns, priv);
+ g_free(priv);
}
/* The bizarre thing about this vtable is that it applies to both
@@ -227,7 +227,7 @@ ns_new(JSContext *context,
if (!ns)
return nullptr;
- priv = g_slice_new0(Ns);
+ priv = g_new0(Ns, 1);
GJS_INC_COUNTER(ns);
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 18f04568..d6f3123a 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -226,7 +226,7 @@ static void repo_finalize(JSFreeOp*, JSObject* obj) {
return; /* we are the prototype, not a real instance */
GJS_DEC_COUNTER(repo);
- g_slice_free(Repo, priv);
+ g_free(priv);
}
/* The bizarre thing about this vtable is that it applies to both
@@ -274,7 +274,7 @@ repo_new(JSContext *context)
if (repo == nullptr)
return nullptr;
- priv = g_slice_new0(Repo);
+ priv = g_new0(Repo, 1);
GJS_INC_COUNTER(repo);
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index f5af889a..5a617f35 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -1062,7 +1062,7 @@ class GIWrapperInstance : public Base {
[[nodiscard]] static Instance* new_for_js_object(JSContext* cx,
JS::HandleObject obj) {
g_assert(!JS_GetPrivate(obj));
- auto* priv = g_slice_new0(Instance);
+ auto* priv = g_new0(Instance, 1);
new (priv) Instance(cx, obj);
// Init the private variable before we do anything else. If a garbage
@@ -1103,7 +1103,7 @@ class GIWrapperInstance : public Base {
protected:
void finalize_impl(JSFreeOp*, JSObject*) {
static_cast<Instance*>(this)->~Instance();
- g_slice_free(Instance, this);
+ g_free(this);
}
// Override if necessary
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index d7780379..a05659ab 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -788,7 +788,7 @@ static void importer_finalize(JSFreeOp*, JSObject* obj) {
return; /* we are the prototype, not a real instance */
GJS_DEC_COUNTER(importer);
- g_slice_free(Importer, priv);
+ g_free(priv);
}
/* The bizarre thing about this vtable is that it applies to both
@@ -839,7 +839,7 @@ importer_new(JSContext *context,
if (!importer)
return nullptr;
- priv = g_slice_new0(Importer);
+ priv = g_new0(Importer, 1);
priv->is_root = is_root;
GJS_INC_COUNTER(importer);