csharp: add move information to EnumerableToAccessor

Still need to fix the converted accessor ownership, maybe by creating a
custom accessor class that released the pinned memory when is freed.
This commit is contained in:
Lauro Moura 2019-12-02 13:58:04 -03:00
parent c9ca2833b8
commit ed6679db19
2 changed files with 20 additions and 4 deletions

View File

@ -770,7 +770,7 @@ struct convert_in_variable_generator
return false;
auto var_name = in_variable_name(param.param_name);
if (!as_generator(
"var " << string << " = " << "Efl.Eo.Globals.IEnumerableToAccessor(" << escape_keyword(param.param_name) << ");\n"
"var " << string << " = Efl.Eo.Globals.IEnumerableToAccessor(" << escape_keyword(param.param_name) << ", " << (param.type.has_own ? "true" : "false")<< ");\n"
).generate(sink, var_name, context))
return false;
}
@ -1314,7 +1314,7 @@ struct native_convert_out_assign_generator
return false;
auto outvar = out_variable_name(param.param_name);
if (!as_generator(
string << " = Efl.Eo.Globals.IEnumerableToAccessor(" << string << ");\n"
string << " = Efl.Eo.Globals.IEnumerableToAccessor(" << string << ", " << (param.type.has_own ? "true" : "false")<< ");\n"
).generate(sink, std::make_tuple(escape_keyword(param.param_name), outvar), context))
return false;
}
@ -1469,7 +1469,7 @@ struct native_convert_return_generator
}
else if (ret_type.c_type == "Eina_Accessor *" || ret_type.c_type == "const Eina_Accessor *")
{
return as_generator("return Efl.Eo.Globals.IEnumerableToAccessor(_ret_var);")
return as_generator(lit("return Efl.Eo.Globals.IEnumerableToAccessor(_ret_var, ") << (ret_type.has_own ? "true" : "false") << ");")
.generate(sink, attributes::unused, context);
}
else if (ret_type.c_type == "Eina_Iterator *" || ret_type.c_type == "const Eina_Iterator *")

View File

@ -774,10 +774,26 @@ public static class Globals
}
}
internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable)
internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable, bool isMoved)
{
if (enumerable == null)
{
throw new ArgumentException("enumerable is null", nameof(enumerable));
}
// If we are a wrapper around an existing Eina.Accessor, we can just forward
// it and avoid unnecessary copying.
var wrappedAccessor = enumerable as Eina.Accessor<T>;
if (wrappedAccessor != null)
{
if (isMoved)
{
wrappedAccessor.Own = false;
}
return wrappedAccessor.Handle;
}
IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
int i = 0;