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 59ddf7fb026e5f4b732f183e37c2ae4d9faae151
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 12:19:12 2026 -0600
eolian_cxx: a callback return value converts with C type and ownership
The generated caller of a function pointer emitted convert_to_c<CxxType>
for its return value: one template argument where three are needed, and
the C++ type in the position the C type belongs. It matches no overload,
so a callback returning something that needs a conversion, a string for
one, could not be compiled at all.
It now emits <c_type, cxx_type, own> the way the argument converter
does.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../grammar/type_function_declaration.hpp | 18 ++++++---
src/tests/eolian_cxx/eolian_cxx_suite.cc | 1 +
src/tests/eolian_cxx/eolian_cxx_suite.h | 1 +
src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc | 47 ++++++++++++++++++++++
src/tests/eolian_cxx/fnptr.c | 30 ++++++++++++++
src/tests/eolian_cxx/fnptr.eo | 25 ++++++++++++
src/tests/eolian_cxx/meson.build | 3 ++
7 files changed, 120 insertions(+), 5 deletions(-)
diff --git a/src/lib/eolian_cxx/grammar/type_function_declaration.hpp b/src/lib/eolian_cxx/grammar/type_function_declaration.hpp
index 123f257464..5fc4eb3b70 100644
--- a/src/lib/eolian_cxx/grammar/type_function_declaration.hpp
+++ b/src/lib/eolian_cxx/grammar/type_function_declaration.hpp
@@ -101,11 +101,19 @@ struct type_function_declaration_generator {
return false;
}
- if (f.return_type != attributes::void_
- && !as_generator(scope_tab << scope_tab << "return ::efl::eolian::convert_to_c<"
- << type << ">(__return_value);\n")
- .generate(sink, f.return_type, ctx))
- return false;
+ /* convert_to_c<c_type, cxx_type[, own]>, as the argument converter. */
+ if (f.return_type != attributes::void_)
+ {
+ attributes::qualifier_def qualifier
+ = f.return_type.original_type.visit(attributes::get_qualifier_visitor{});
+
+ if (!as_generator(scope_tab << scope_tab << "return ::efl::eolian::convert_to_c<"
+ << c_type << ", " << type
+ << ((qualifier & attributes::qualifier_info::is_own) ? ", true" : "")
+ << ">(__return_value);\n")
+ .generate(sink, std::make_tuple(f.return_type, f.return_type), ctx))
+ return false;
+ }
if (!as_generator(scope_tab << "}\n").generate(sink, attributes::unused, ctx))
return false;
diff --git a/src/tests/eolian_cxx/eolian_cxx_suite.cc b/src/tests/eolian_cxx/eolian_cxx_suite.cc
index d307ff1bef..ad850e6e04 100644
--- a/src/tests/eolian_cxx/eolian_cxx_suite.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_suite.cc
@@ -29,6 +29,7 @@ static const Efl_Test_Case etc[] = {
{ "Eolian-Cxx Binding", eolian_cxx_test_binding },
{ "Eolian-Cxx Cyclic", eolian_cxx_test_cyclic },
{ "Eolian-Cxx Documentation", eolian_cxx_test_documentation },
+ { "Eolian-Cxx Callbacks", eolian_cxx_test_callbacks },
{ NULL, NULL }
};
diff --git a/src/tests/eolian_cxx/eolian_cxx_suite.h b/src/tests/eolian_cxx/eolian_cxx_suite.h
index 53cec1a0f8..943b2a621f 100644
--- a/src/tests/eolian_cxx/eolian_cxx_suite.h
+++ b/src/tests/eolian_cxx/eolian_cxx_suite.h
@@ -11,5 +11,6 @@ void eolian_cxx_test_inheritance(TCase* tc);
void eolian_cxx_test_binding(TCase* tc);
void eolian_cxx_test_cyclic(TCase* tc);
void eolian_cxx_test_documentation(TCase* tc);
+void eolian_cxx_test_callbacks(TCase* tc);
#endif /* _EOLIAN_CXX_SUITE_H */
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc b/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc
new file mode 100644
index 0000000000..bd9887f298
--- /dev/null
+++ b/src/tests/eolian_cxx/eolian_cxx_test_callbacks.cc
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2019 by its authors. See AUTHORS.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <Eo.hh>
+
+#define EOLIANCXXTEST_API
+#define EOLIANCXXTEST_API_WEAK
+
+#include <fnptr.eo.hh>
+#include <fnptr.eo.impl.hh>
+
+#include "eolian_cxx_suite.h"
+/* A callback returning a string converts what the lambda returns, which
+ * takes the C type, the C++ type and the ownership. */
+EFL_START_TEST(eolian_cxx_test_callbacks_return_string)
+{
+ efl::eo::eo_init init;
+
+ nonamespace::Fnptr obj(efl::eo::instantiate);
+
+ std::string r = obj.text([](int x) { return x ? "some" : "none"; }, 7);
+
+ ck_assert_str_eq(r.c_str(), "some");
+}
+EFL_END_TEST
+
+void
+eolian_cxx_test_callbacks(TCase* tc)
+{
+ tcase_add_test(tc, eolian_cxx_test_callbacks_return_string);
+}
diff --git a/src/tests/eolian_cxx/fnptr.c b/src/tests/eolian_cxx/fnptr.c
new file mode 100644
index 0000000000..f9cb74ca5c
--- /dev/null
+++ b/src/tests/eolian_cxx/fnptr.c
@@ -0,0 +1,30 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <Eo.h>
+#include <Ecore.h>
+
+#define EOLIANCXXTEST_API
+#define EOLIANCXXTEST_API_WEAK
+
+#include "fnptr.eo.h"
+
+#define MY_CLASS FNPTR_CLASS
+
+static const char *
+_fnptr_text(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED,
+ void *cb_data, Fnptr_Text_Func cb, Eina_Free_Cb cb_free_cb,
+ int value)
+{
+ const char *text = NULL;
+
+ if (cb) text = cb(cb_data, value);
+ if (cb_free_cb) cb_free_cb(cb_data);
+
+ return text;
+}
+
+#include "fnptr.eo.c"
diff --git a/src/tests/eolian_cxx/fnptr.eo b/src/tests/eolian_cxx/fnptr.eo
new file mode 100644
index 0000000000..5be9a0f961
--- /dev/null
+++ b/src/tests/eolian_cxx/fnptr.eo
@@ -0,0 +1,25 @@
+function Fnptr_Text_Func {
+ [[A callback returning a string. @since 1.66]]
+ params {
+ @in x: int; [[The argument.]]
+ }
+ return: string; [[The text.]]
+};
+
+class Fnptr extends Efl.Object {
+ [[A class with methods taking function pointers. @since 1.66]]
+ data: null;
+ methods {
+ text {
+ [[Calls $cb with $value and returns what it returned.
+
+ The callback is freed through its free function before the
+ method returns, unless it is $null. @since 1.66]]
+ params {
+ @in cb: Fnptr_Text_Func; [[Called with $value.]]
+ @in value: int; [[The value to pass it.]]
+ }
+ return: string; [[The text $cb returned.]]
+ }
+ }
+}
diff --git a/src/tests/eolian_cxx/meson.build b/src/tests/eolian_cxx/meson.build
index a5b784d12c..b4c5434323 100644
--- a/src/tests/eolian_cxx/meson.build
+++ b/src/tests/eolian_cxx/meson.build
@@ -20,6 +20,8 @@ eolian_cxx_suite_src = files([
'eolian_cxx_test_cyclic.cc',
'complex.c',
'complex_cxx.cc',
+ 'eolian_cxx_test_callbacks.cc',
+ 'fnptr.c',
'eolian_cxx_suite.h'
])
@@ -31,6 +33,7 @@ pub_eo_files = [
'cyclic1.eo',
'cyclic2.eo',
'docs.eo',
+ 'fnptr.eo',
'generic.eo',
'generic_interface.eo',
'name1_name2_type_generation.eo',
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.