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 4cc8f9d94d0c1e3b8c377968c519f097a57f91f9
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 14 11:47:59 2026 -0600
eolian_cxx: an object out parameter is referenced, or adopted with @move
An object given back through a borrowed @out parameter was put in the
C++ wrapper without a reference, but the wrapper drops one when it
dies: Efl.Ui.Relative_Container.relation_left_get and the other
relation getters took a reference away from the container each time
their base came back to C++.
The wrapper now takes a reference of its own. An object out parameter
given with @move, whose reference is the caller's, did not compile at
all for want of an overload; it is now adopted.
The test fixture gets one of each, Fnptr.self_out and Fnptr.fresh_out.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bindings/cxx/eo_cxx/eo_cxx_interop.hh | 21 +++++++++--
src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc | 43 +++++++++++++++++++++++
src/tests/eolian_cxx/fnptr.c | 12 +++++++
src/tests/eolian_cxx/fnptr.eo | 12 +++++++
4 files changed, 86 insertions(+), 2 deletions(-)
diff --git a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
index f49fb61b86..ee0c7ce487 100644
--- a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
+++ b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
@@ -148,15 +148,30 @@ void assign_out_impl(T& lhs, T& rhs, tag<T&, T>)
{
lhs = rhs;
}
+// Borrowed: C keeps its reference, the wrapper takes one of its own, which
+// is the one it drops.
template <typename T>
void assign_out_impl(T& lhs, Eo* rhs, tag<T&, Eo*>
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
{
- lhs._reset(rhs);
+ lhs._reset(eo::detail::ref(rhs));
}
template <typename T>
void assign_out_impl(T& lhs, Eo const* rhs, tag<T&, Eo const*>
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
+{
+ lhs._reset(const_cast<Eo*>(eo::detail::ref(rhs)));
+}
+// Given with @move: the reference C gives is the wrapper's.
+template <typename T>
+void assign_out_impl(T& lhs, Eo* rhs, tag<T&, Eo*, true>
+ , typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
+{
+ lhs._reset(const_cast<Eo*>(rhs));
+}
+template <typename T>
+void assign_out_impl(T& lhs, Eo const* rhs, tag<T&, Eo const*, true>
+ , typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
{
lhs._reset(const_cast<Eo*>(rhs));
}
@@ -182,11 +197,13 @@ void assign_out_impl(T*& lhs, T& rhs, tag<T*, T>) // optional
if(lhs)
*lhs = rhs;
}
+// The generator only makes this for owned values, hence the forced Own; an
+// object keeps its own, so a borrowed one is referenced, not adopted.
template <typename T, typename Rhs, typename U, typename O, bool B>
void assign_out_impl(efl::eina::optional<T>& lhs, Rhs& rhs, tag<efl::eina::optional<U&>, O, B>)
{
if(lhs)
- assign_out<U&, O, true>(*lhs, rhs);
+ assign_out<U&, O, eo::is_eolian_object<U>::value ? B : true>(*lhs, rhs);
}
template <typename Tag>
void assign_out_impl(eina::value& lhs, Eina_Value& rhs, Tag)
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc b/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc
index ddd246fe5a..89d794db6b 100644
--- a/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc
@@ -182,6 +182,48 @@ EFL_START_TEST(eolian_cxx_test_callbacks_lent_iterator)
}
EFL_END_TEST
+/* An object out parameter: a borrowed one gets a reference of the wrapper's
+ * own, so dropping the wrapper leaves the object as it was; one given with
+ * @move is adopted, so dropping the wrapper frees it. */
+EFL_START_TEST(eolian_cxx_test_out_object)
+{
+ efl::eo::eo_init init;
+
+ nonamespace::Fnptr obj(efl::eo::instantiate);
+ Eo* raw = obj._eo_ptr();
+ int refs = efl_ref_count(raw);
+ {
+ nonamespace::Fnptr o;
+ obj.self_out(o);
+ ck_assert_ptr_eq(o._eo_ptr(), raw);
+ ck_assert_int_eq(efl_ref_count(raw), refs + 1);
+ }
+ ck_assert_int_eq(efl_ref_count(raw), refs);
+
+ /* Through an optional out, as a hand-written binding may use: still
+ * borrowed, so still referenced. */
+ {
+ nonamespace::Fnptr o;
+ efl::eina::optional<nonamespace::Fnptr&> opt(o);
+ efl::eolian::assign_out<efl::eina::optional<nonamespace::Fnptr&>, Eo*>(opt, raw);
+ ck_assert_ptr_eq(o._eo_ptr(), raw);
+ ck_assert_int_eq(efl_ref_count(raw), refs + 1);
+ }
+ ck_assert_int_eq(efl_ref_count(raw), refs);
+
+ Eo* fresh = nullptr;
+ {
+ nonamespace::Fnptr o;
+ obj.fresh_out(o);
+ fresh = o._eo_ptr();
+ ck_assert_ptr_ne(fresh, NULL);
+ efl_wref_add(fresh, &fresh);
+ ck_assert_int_eq(efl_ref_count(fresh), 1);
+ }
+ ck_assert_ptr_eq(fresh, NULL);
+}
+EFL_END_TEST
+
static int _callbacks_log_errors = 0;
static void
@@ -337,6 +379,7 @@ void
eolian_cxx_test_callbacks(TCase* tc)
{
tcase_add_test(tc, eolian_cxx_test_callbacks_return_string);
+ tcase_add_test(tc, eolian_cxx_test_out_object);
tcase_add_test(tc, eolian_cxx_test_callbacks_kept_alive_at_no_reference);
tcase_add_test(tc, eolian_cxx_test_callbacks_null_wrapper_not_dying);
tcase_add_test(tc, eolian_cxx_test_callbacks_object_being_destroyed);
diff --git a/src/tests/eolian_cxx/fnptr.c b/src/tests/eolian_cxx/fnptr.c
index 61e12e2e3c..8e3a5464b3 100644
--- a/src/tests/eolian_cxx/fnptr.c
+++ b/src/tests/eolian_cxx/fnptr.c
@@ -82,6 +82,18 @@ _fnptr_sum_lent(Eo *obj EINA_UNUSED, Fnptr_Data *pd EINA_UNUSED, Eina_Iterator *
return sum;
}
+static void
+_fnptr_self_out(Eo *obj, Fnptr_Data *pd EINA_UNUSED, Eo **o)
+{
+ *o = obj;
+}
+
+static void
+_fnptr_fresh_out(Eo *obj EINA_UNUSED, Fnptr_Data *pd EINA_UNUSED, Eo **o)
+{
+ *o = efl_add_ref(FNPTR_CLASS, NULL);
+}
+
static int
_fnptr_format(Eo *obj EINA_UNUSED, Fnptr_Data *pd EINA_UNUSED,
void *cb_data, Fnptr_Format_Func cb, Eina_Free_Cb cb_free_cb)
diff --git a/src/tests/eolian_cxx/fnptr.eo b/src/tests/eolian_cxx/fnptr.eo
index 0302cc198e..62c1494bf9 100644
--- a/src/tests/eolian_cxx/fnptr.eo
+++ b/src/tests/eolian_cxx/fnptr.eo
@@ -98,6 +98,18 @@ class Fnptr extends Efl.Object {
}
return: int; [[The sum.]]
}
+ self_out {
+ [[Gives itself back through $o, keeping its reference.]]
+ params {
+ @out o: Fnptr; [[This object, borrowed.]]
+ }
+ }
+ fresh_out {
+ [[Gives a new object through $o, with its only reference.]]
+ params {
+ @out o: Fnptr @move; [[A new object the caller owns.]]
+ }
+ }
format {
[[Calls $cb with a buffer and the int 42, and returns 1 when what $cb
wrote into the buffer is "value 42", 0 when it is anything else
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.