WIP - Start changing the MarshalType for non-owned string returned

This commit is contained in:
Lauro Moura 2019-12-10 18:29:26 -03:00
parent 590cd74906
commit 23cf1162f2
2 changed files with 22 additions and 1 deletions

View File

@ -50,6 +50,8 @@ struct marshall_type_visitor_generate
{
using attributes::regular_type_def;
auto is_native_dir = marshall_direction::current_direction(*context) == marshall_direction::native_to_managed;
struct match
{
eina::optional<std::string> name;
@ -69,6 +71,12 @@ struct marshall_type_visitor_generate
{
regular_type_def r = regular;
r.base_qualifier.qualifier ^= qualifier_info::is_ref;
// Non-owned strings returned will be manually handled
// due to lifetime issues.
if (is_native_dir && (is_out || is_return))
return replace_base_type(r, "System.IntPtr");
return replace_base_type(r, "System.String");
}}
, {"mstring", true, [&]
@ -81,6 +89,12 @@ struct marshall_type_visitor_generate
{
regular_type_def r = regular;
r.base_qualifier.qualifier ^= qualifier_info::is_ref;
// Non-owned strings returned will be manually handled
// due to lifetime issues.
if (is_native_dir && (is_out || is_return))
return replace_base_type(r, "System.IntPtr");
return replace_base_type(r, "System.String");
}}
, {"stringshare", true, [&]

View File

@ -834,6 +834,7 @@ struct convert_out_variable_generator
} const convert_out_variable {};
// Generates intermediate @out variables for native method wrappers (wrappers that are called from C)
struct native_convert_out_variable_generator
{
template <typename OutputIterator, typename Context>
@ -850,13 +851,19 @@ struct native_convert_out_variable_generator
).generate(sink, std::make_tuple(param, out_variable_name(param.param_name), param), context);
}
else if (helpers::need_struct_conversion(regular)
|| param_is_acceptable(param, "const char *", !WANT_OWN, WANT_OUT)
|| param_is_acceptable(param, "Eina_Stringshare *", !WANT_OWN, WANT_OUT))
{
return as_generator(
type << " " << string << " = default(" << type << ");\n"
).generate(sink, std::make_tuple(param, out_variable_name(param.param_name), param), context);
}
else if (param_is_acceptable(param, "const char *", !WANT_OWN, WANT_OUT))
{
// FIXME Replace with IntPtr interemediate variable
return as_generator(
type << " " << string << " = default(" << type << ");\n"
).generate(sink, std::make_tuple(param, out_variable_name(param.param_name), param), context);
}
else if (param_is_acceptable(param, "Eina_Binbuf *", WANT_OWN, WANT_OUT)
|| param_is_acceptable(param, "Eina_Binbuf *", !WANT_OWN, WANT_OUT)
|| param_is_acceptable(param, "const Eina_Binbuf *", WANT_OWN, WANT_OUT)