This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 2f6ba3fe0815a3791b998de24808367129754e27
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 11 21:10:37 2026 -0600
cxx: a wrapper around a class does not reference it
An efl::Class holds the id of a class, and efl_ref and efl_unref on a
class id are errors: every copy and every destruction of the wrapper
logged one, which made efl::Class unusable, for instance to give a
factory its item class. The wrappers now leave classes alone, which
live as long as Eo does.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bindings/cxx/eo_cxx/eo_ops.hh | 17 +++++++++---
src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc | 35 +++++++++++++++++++++++++
2 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/src/bindings/cxx/eo_cxx/eo_ops.hh b/src/bindings/cxx/eo_cxx/eo_ops.hh
index 6d09a4fa99..5aff26389c 100644
--- a/src/bindings/cxx/eo_cxx/eo_ops.hh
+++ b/src/bindings/cxx/eo_cxx/eo_ops.hh
@@ -36,22 +36,33 @@ shutdown()
::efl_object_shutdown();
}
+/* A class is an Eo id as well, but it lives as long as Eo does and cannot be
+ * referenced: efl_ref and efl_unref on one are errors. An efl::Class is a
+ * wrapper like any other and is copied and destroyed like one, so what the
+ * wrappers hold is told apart here. */
+inline bool
+is_class(const Eo *obj)
+{
+ return ::efl_class_get(obj) == EFL_CLASS_CLASS;
+}
+
inline Eo*
ref(Eo *obj)
{
- return ::efl_ref(obj);
+ return is_class(obj) ? obj : ::efl_ref(obj);
}
inline const Eo*
ref(const Eo *obj)
{
- return ::efl_ref(obj);
+ return is_class(obj) ? obj : ::efl_ref(obj);
}
inline void
unref(const Eo *obj)
{
- ::efl_unref(obj);
+ if (!is_class(obj))
+ ::efl_unref(obj);
}
inline void
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
index 8c4c15ae3c..2d1e8916fa 100644
--- a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
@@ -76,9 +76,44 @@ EFL_START_TEST(eolian_cxx_test_wrapper_converts_to_base)
}
EFL_END_TEST
+static int _logged_errors;
+
+static void
+_count_errors(const Eina_Log_Domain *domain EINA_UNUSED, Eina_Log_Level level,
+ const char *file EINA_UNUSED, const char *fnc EINA_UNUSED,
+ int line EINA_UNUSED, const char *fmt EINA_UNUSED,
+ void *data EINA_UNUSED, va_list args EINA_UNUSED)
+{
+ if (level == EINA_LOG_LEVEL_ERR) _logged_errors++;
+}
+
+/* A class is an Eo id that cannot be referenced: copying and destroying a
+ * wrapper of one must not try. */
+EFL_START_TEST(eolian_cxx_test_wrapper_class_is_not_referenced)
+{
+ efl::eo::eo_init init;
+
+ _logged_errors = 0;
+ eina_log_print_cb_set(_count_errors, NULL);
+ {
+ ::efl::eo::concrete first(const_cast<Eo*>(EFL_OBJECT_CLASS));
+ ::efl::eo::concrete copy(first);
+ ::efl::eo::concrete assigned(nullptr);
+
+ assigned = first;
+ fail_if(copy._eo_ptr() != EFL_OBJECT_CLASS);
+ fail_if(assigned._eo_ptr() != EFL_OBJECT_CLASS);
+ }
+ eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+
+ ck_assert_int_eq(_logged_errors, 0);
+}
+EFL_END_TEST
+
void
eolian_cxx_test_wrapper(TCase* tc)
{
tcase_add_test(tc, eolian_cxx_test_wrapper_size);
tcase_add_test(tc, eolian_cxx_test_wrapper_converts_to_base);
+ tcase_add_test(tc, eolian_cxx_test_wrapper_class_is_not_referenced);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.