[gjs: 12/18] maint: Mark parameters maybe_unused if only used in asserts
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 12/18] maint: Mark parameters maybe_unused if only used in asserts
- Date: Mon, 5 Oct 2020 02:09:53 +0000 (UTC)
commit b68f9c9ceba96485c98fc53b9ca7470ff8754848
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Sep 20 09:03:50 2020 -0700
maint: Mark parameters maybe_unused if only used in asserts
This is in order to support compilation with G_DISABLE_ASSERT.
gi/closure.cpp | 3 ++-
gi/object.cpp | 7 ++++---
gjs/context.cpp | 11 ++++++-----
gjs/jsapi-util.h | 4 ++--
4 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/gi/closure.cpp b/gi/closure.cpp
index 052ed8a9..bd98390b 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -86,7 +86,8 @@ invalidate_js_pointers(GjsClosure *gc)
g_closure_invalidate(&gc->base);
}
-static void global_context_finalized(JS::HandleFunction func, void* data) {
+static void global_context_finalized(JS::HandleFunction func [[maybe_unused]],
+ void* data) {
GjsClosure *gc = (GjsClosure*) data;
Closure *c = &gc->priv;
diff --git a/gi/object.cpp b/gi/object.cpp
index 25399cfa..fd338090 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1796,11 +1796,12 @@ void ObjectInstance::associate_closure(JSContext* cx, GClosure* closure) {
if (!is_prototype())
to_instance()->ensure_uses_toggle_ref(cx);
+ g_assert(std::find(m_closures.begin(), m_closures.end(), closure) ==
+ m_closures.end() &&
+ "This closure was already associated with this object");
+
/* This is a weak reference, and will be cleared when the closure is
* invalidated */
- auto already_has = std::find(m_closures.begin(), m_closures.end(), closure);
- g_assert(already_has == m_closures.end() &&
- "This closure was already associated with this object");
m_closures.push_front(closure);
g_closure_add_invalidate_notifier(
closure, this, &ObjectInstance::closure_invalidated_notify);
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 898d1eae..401583c7 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -496,9 +496,9 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
g_error("Failed to create root importer");
}
- JS::Value v_importer = gjs_get_global_slot(global, GjsGlobalSlot::IMPORTS);
- g_assert(((void) "Someone else already created root importer",
- v_importer.isUndefined()));
+ g_assert(
+ gjs_get_global_slot(global, GjsGlobalSlot::IMPORTS).isUndefined() &&
+ "Someone else already created root importer");
gjs_set_global_slot(global, GjsGlobalSlot::IMPORTS,
JS::ObjectValue(*importer));
@@ -676,7 +676,7 @@ JSObject* GjsContextPrivate::getIncumbentGlobal(JSContext* cx) {
/* See engine.cpp and JS::SetEnqueuePromiseJobCallback(). */
bool GjsContextPrivate::enqueuePromiseJob(
- JSContext* cx, JS::HandleObject promise [[maybe_unused]],
+ JSContext* cx [[maybe_unused]], JS::HandleObject promise [[maybe_unused]],
JS::HandleObject job, JS::HandleObject allocation_site [[maybe_unused]],
JS::HandleObject incumbent_global [[maybe_unused]]) {
g_assert(cx == m_cx);
@@ -815,7 +815,8 @@ void GjsContextPrivate::register_unhandled_promise_rejection(
}
void GjsContextPrivate::unregister_unhandled_promise_rejection(uint64_t id) {
- size_t erased = m_unhandled_rejection_stacks.erase(id);
+ // Return value unused in G_DISABLE_ASSERT case
+ [[maybe_unused]] size_t erased = m_unhandled_rejection_stacks.erase(id);
g_assert(((void)"Handler attached to rejected promise that wasn't "
"previously marked as unhandled", erased == 1));
}
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 40cfbac2..d84611be 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -159,8 +159,8 @@ struct GjsAutoCallableInfo : GjsAutoBaseInfo {
private:
void validate() const {
- if (GIBaseInfo* base = *this)
- g_assert(GI_IS_CALLABLE_INFO(base));
+ if (*this)
+ g_assert(GI_IS_CALLABLE_INFO(get()));
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]