diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2020-09-10 05:33:19 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2020-09-10 05:33:19 +0000 |
commit | 8836e6ce41f8774cc571239f4a34f77d648f1f6f (patch) | |
tree | 1f71367fae8ece1bad4dd8b67bef065c200f3d03 | |
parent | e8287711aa24fc96924e5f9fe05678186d52903a (diff) | |
parent | e54ba8eb11bb652e2b9b4126dacc5ccad4752dbb (diff) | |
download | gjs-8836e6ce41f8774cc571239f4a34f77d648f1f6f.tar.gz |
Merge branch 'remove-gslice' into 'master'
cleanup: Don't use GSlice anywhere
See merge request GNOME/gjs!488
-rw-r--r-- | gi/arg-cache.cpp | 13 | ||||
-rw-r--r-- | gi/arg-inl.h | 9 | ||||
-rw-r--r-- | gi/arg.cpp | 11 | ||||
-rw-r--r-- | gi/boxed.cpp | 6 | ||||
-rw-r--r-- | gi/function.cpp | 8 | ||||
-rw-r--r-- | gi/ns.cpp | 4 | ||||
-rw-r--r-- | gi/repo.cpp | 4 | ||||
-rw-r--r-- | gi/wrapperutils.h | 4 | ||||
-rw-r--r-- | gjs/importer.cpp | 4 |
9 files changed, 34 insertions, 29 deletions
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp index d49576ef..2343822b 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/arg-inl.h b/gi/arg-inl.h index 06330884..852bf904 100644 --- a/gi/arg-inl.h +++ b/gi/arg-inl.h @@ -35,6 +35,8 @@ // gjs_arg_set(GIArgument*, T) - sets the appropriate union member for type T. // gjs_arg_unset<T>(GIArgument*) - sets the appropriate zero value in the // appropriate union member for type T. +// gjs_arg_steal<T>(GIArgument*) - sets the appropriate zero value in the +// appropriate union member for type T and returns the replaced value. template <typename T> [[nodiscard]] inline decltype(auto) gjs_arg_member(GIArgument* arg, @@ -163,6 +165,13 @@ inline void gjs_arg_unset(GIArgument* arg) { gjs_arg_set<T, TAG>(arg, static_cast<T>(0)); } +template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID> +[[nodiscard]] inline T gjs_arg_steal(GIArgument* arg) { + auto val = gjs_arg_get<T, TAG>(arg); + gjs_arg_unset<T, TAG>(arg); + return val; +} + // Implementation to store rounded (u)int64_t numbers into double template <typename BigT> @@ -3395,17 +3395,13 @@ gjs_g_arg_release_internal(JSContext *context, } else if (g_type_is_a(gtype, G_TYPE_VALUE)) { /* G_TYPE_VALUE is-a G_TYPE_BOXED, but we special case it */ if (g_type_info_is_pointer (type_info)) - g_boxed_free( - gtype, - g_steal_pointer(&gjs_arg_member<void*>(arg))); + g_boxed_free(gtype, gjs_arg_steal<void*>(arg)); else g_clear_pointer(&gjs_arg_member<GValue*>(arg), g_value_unset); } else if (g_type_is_a(gtype, G_TYPE_BOXED)) { if (transfer != TRANSFER_IN_NOTHING) - g_boxed_free( - gtype, - g_steal_pointer(&gjs_arg_member<void*>(arg))); + g_boxed_free(gtype, gjs_arg_steal<void*>(arg)); } else if (g_type_is_a(gtype, G_TYPE_VARIANT)) { if (transfer != TRANSFER_IN_NOTHING) g_clear_pointer(&gjs_arg_member<GVariant*>(arg), @@ -3419,8 +3415,7 @@ gjs_g_arg_release_internal(JSContext *context, if (transfer != TRANSFER_IN_NOTHING) { auto* priv = FundamentalPrototype::for_gtype(context, gtype); - priv->call_unref_function( - g_steal_pointer(&gjs_arg_member<void*>(arg))); + priv->call_unref_function(gjs_arg_steal<void*>(arg)); } } else { gjs_throw(context, "Unhandled GType %s releasing GArgument", diff --git a/gi/boxed.cpp b/gi/boxed.cpp index b1d66a94..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"); @@ -376,7 +376,7 @@ bool BoxedInstance::constructor_impl(JSContext* context, JS::HandleObject obj, return false; } - own_ptr(g_steal_pointer(&gjs_arg_member<void*>(&rval_arg))); + own_ptr(gjs_arg_steal<void*>(&rval_arg)); debug_lifecycle("Boxed pointer created from zero-args constructor"); @@ -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 5814de85..585c3ce0 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; @@ -1101,7 +1101,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 @@ -1325,7 +1325,7 @@ function_new(JSContext *context, return NULL; } - priv = g_slice_new0(Function); + priv = g_new0(Function, 1); GJS_INC_COUNTER(function); @@ -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); |