mono / gtk-sharp

Gtk# is a Mono/.NET binding to the cross platform Gtk+ GUI toolkit and the foundation of most GUI apps built with Mono
http://www.mono-project.com/GtkSharp
Other
428 stars 140 forks source link

[Generator] Don't try to reconstruct the value on a struct parameter … #148

Closed Therzok closed 8 years ago

Therzok commented 8 years ago

…passed by value

In the case of TreeStore.GetValue, the generated code would try to assign iter to the value that was marshalled back from native.

This behaviour is incorrect, as the struct was passed by value, and discarded, having no effect on the code-flow but useless overhead.

public void GetValue(Gtk.TreeIter, int column, ref GLib.Value value) {
    IntPtr native_iter = GLib.Marshaller.StructureToPtrAlloc (iter);
    IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
    gtk_tree_model_get_value(Handle, native_iter, column, native_value);
    // The line below is removed.
    native_iter = TreeIter.New (native_iter);
    Marshal.FreeHGlobal (native_iter);
    value = (GLib.Value) Marshal.PtrToStructure (native_value, typeof (GLib.Value));
    Marshal.FreeHGlobal (native_value);
}
Therzok commented 8 years ago

/cc @DavidKarlas

Therzok commented 8 years ago

The full diff https://gist.github.com/Therzok/22ebd51501225e108099fd5d59e6b0b2

DavidKarlas commented 8 years ago

Awesome job!

knocte commented 8 years ago

Yeah definitely, can you guys port to master? :)

Therzok commented 8 years ago

I'm doing that now.

Therzok commented 8 years ago

658f2e2eb5833807e4d54c7f6b90a681afd112dc