Ryujinx-GtkSharp/glib/Opaque.cs

140 lines
2.8 KiB
C#
Raw Normal View History

2002-07-30 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
2002-07-31 01:02:12 +02:00
// Opaque .cs - Opaque struct wrapper implementation
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
//
// Authors: Bob Smith <bob@thestuff.net>
// Mike Kestner <mkestner@speakeasy.net>
2002-07-30 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
2002-07-31 01:02:12 +02:00
// Rachel Hestilow <hestilow@ximian.com>
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
//
// Copyright (c) 2001 Bob Smith
// Copyright (c) 2001 Mike Kestner
// Copyright (c) 2002 Rachel Hestilow
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
namespace GLib {
using System;
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
public class Opaque : IWrapper, IDisposable {
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
IntPtr _obj;
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
bool owned;
public static Opaque GetOpaque (IntPtr o, Type type, bool owned)
{
if (o == IntPtr.Zero)
return null;
Opaque opaque = (Opaque)Activator.CreateInstance (type, new object[] { o });
if (owned) {
if (opaque.owned) {
// The constructor took a Ref it shouldn't have, so undo it
opaque.Unref (o);
}
opaque.owned = true;
} else
opaque = opaque.Copy (o);
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
return opaque;
}
public Opaque ()
{
owned = true;
}
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
public Opaque (IntPtr raw)
{
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
owned = false;
Raw = raw;
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
}
protected IntPtr Raw {
get {
return _obj;
}
set {
if (_obj == value) {
return;
}
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
if (_obj != IntPtr.Zero) {
Unref (_obj);
if (owned)
Free (_obj);
}
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
_obj = value;
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
if (_obj != IntPtr.Zero) {
Ref (_obj);
}
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
}
}
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
public virtual void Dispose ()
{
Raw = IntPtr.Zero;
GC.SuppressFinalize (this);
}
// These take an IntPtr arg so we don't get conflicts if we need
// to have an "[Obsolete] public void Ref ()"
protected virtual void Ref (IntPtr raw) {}
protected virtual void Unref (IntPtr raw) {}
protected virtual void Free (IntPtr raw) {}
protected virtual Opaque Copy (IntPtr raw)
{
return this;
}
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
public IntPtr Handle {
get {
return _obj;
}
}
public IntPtr OwnedCopy {
get {
Opaque result = Copy (Handle);
result.Owned = false;
return result.Handle;
}
}
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 20:45:21 +02:00
public bool Owned {
get {
return owned;
}
set {
owned = value;
}
}
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 08:08:52 +02:00
public override bool Equals (object o)
{
if (!(o is Opaque))
return false;
return (Handle == ((Opaque) o).Handle);
}
public override int GetHashCode ()
{
return Handle.GetHashCode ();
}
}
}