diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-02 13:58:04 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-03 18:07:05 -0300 |
commit | ed6679db1901c710cc6ddb50e7001cfd20caa77a (patch) | |
tree | 96434e0fc38328b7c76121150b48435085e4599c | |
parent | c9ca2833b82fe080bf3fe979bda75931871b5d0f (diff) | |
download | efl-ed6679db1901c710cc6ddb50e7001cfd20caa77a.tar.gz |
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.
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/parameter.hh | 6 | ||||
-rw-r--r-- | src/bindings/mono/eo_mono/iwrapper.cs | 18 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh b/src/bin/eolian_mono/eolian/mono/parameter.hh index 3d072614d5..b6e4f32aea 100644 --- a/src/bin/eolian_mono/eolian/mono/parameter.hh +++ b/src/bin/eolian_mono/eolian/mono/parameter.hh @@ -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 *") diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index 32f51e2936..e19e594725 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs @@ -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; |