Fixed issue [#1240]: "Generic ref and out wrappers do not copy results to the reference parameter", by assigning the GCHandle.Target back to the reference parameter.

This commit is contained in:
the_fiddler 2009-10-17 20:02:53 +00:00
parent b2bc058ac9
commit 353ef37dd4
2 changed files with 238 additions and 3 deletions

View file

@ -422,7 +422,9 @@ namespace Bind.Structures
handle_release_statements.Add(String.Format("{0}_ptr.Free();", p.Name)); handle_release_statements.Add(String.Format("{0}_ptr.Free();", p.Name));
if (p.Flow == FlowDirection.Out) // Due to the GCHandle-style pinning (which boxes value types), we need to assign the modified
// value back to the reference parameter (but only if it has an out or in/out flow direction).
if ((p.Flow == FlowDirection.Out || p.Flow == FlowDirection.Undefined) && p.Reference)
{ {
assign_statements.Add(String.Format( assign_statements.Add(String.Format(
"{0} = ({1}){0}_ptr.Target;", "{0} = ({1}){0}_ptr.Target;",
@ -444,7 +446,12 @@ namespace Bind.Structures
p.Array > 0 ? p.Name : "&" + p.Name, p.Array > 0 ? p.Name : "&" + p.Name,
indirection_levels[p.IndirectionLevel])); indirection_levels[p.IndirectionLevel]));
if (p.Flow == FlowDirection.Out && p.Array == 0) // Fixed Arrays of blittable types don't need explicit assignment. if (p.Name == "pixels_ptr")
System.Diagnostics.Debugger.Break();
// Arrays are not value types, so we don't need to do anything for them.
// Pointers are passed directly by value, so we don't need to assign them back either (they don't change).
if ((p.Flow == FlowDirection.Out || p.Flow == FlowDirection.Undefined) && p.Reference)
{ {
assign_statements.Add(String.Format("{0} = *{0}_ptr;", p.Name)); assign_statements.Add(String.Format("{0} = *{0}_ptr;", p.Name));
} }

File diff suppressed because it is too large Load diff