Commit Graph

19 Commits

Author SHA1 Message Date
Bertrand Lorentz
e48ac63d54 generator: Dispose ownable method parameters in VM callback (bxc#237)
Some virtual methods are passed a native object that is wrapped in an
IDisposable managed object, which is then passed on to the managed
overrides. We need to dispose those objects as soon as possible,
otherwise their native counterpart will not be freed until the next
garbage collection. Requiring the overrides to dispose them would be
cumbersome and error-prone.

Those parameters will now be disposed in a finally {...} block, after
the virtual method has returned. This means that overrides should not
keep a reference to such a parameter outside of the scope of the method,
as it will be diposed when the method returns.

This change only affects Cairo.Context parameter for now, but it was
particularly needed for them, as they could happily hold on to tens of
MBs of memory until the next garbage collection.
2013-11-09 16:26:17 +01:00
Bertrand Lorentz
15c5820cd8 generator: Rework data structures used by ManagedCallString
Use a single dictionary to hold the parameters and mark them as special,
instead of maintaining two lists in parallel.
2012-11-04 16:58:49 +01:00
Mike Kestner
c6a3bf4b73 Fix TextBufferSerializeFunc signature
* generator/CallbackGen.cs: connect return value count parameters
* generator/ManagedCallString.cs: out count params aren't special
* generator/MethodBody.cs: don't finish hidden params
* generator/Parameters.cs: explicit IsCount setting support, with
    Parameters.GetCountParameter(name) interface. Clear IsCount
    values during validation if they have no associated array. Any
    remaining count params must be associated with a retval, so
    hide them.
* generator/ReturnValue.cs: support array_length_param attribute to
    associate a return value with a "count" param.  Use new helper
    methods to marshal these array retvals to IntPtr and back.
* glib/Marshaller.cs: support for byte[] marshaling to and from
    IntPtr using a count and type in the from native direction.
* gtk/Gtk.metadata: mark TextBufferSerializeFunc return type as
    an array with the length specific in the length param.
2011-04-28 18:38:07 -05:00
Christian Hoff
08b43fbd76 2009-08-13 Christian Hoff <christian_hoff@gmx.net>
* generator/IGeneratable.cs: Remove MarshalReturnType, ToNativeReturnType,
	FromNativeReturn and ToNativeReturn as they never returned something else
	than MarshalType, FromNative/AllocNative and CallByName, respectively.
	* generator/Signal.cs: Use AllocNative for IManualMarshalers.

svn path=/trunk/gtk-sharp/; revision=139849
2009-08-13 14:46:33 +00:00
Christian Hoff
291ee61b2d 2009-04-13 Christian Hoff <christian_hoff@gmx.net>
Add support for virtual methods(vm) to the generator.

	* parser/gapi2xml.pl: Generate a class_struct element with
	all members of the class structure. Dump the first (instance)
	parameter for signal and vm elements. Bump up parser version.
	* generator/GObjectVM.cs: Added. Support for GObject virtual methods.
	* generator/DefaultSignalHandler.cs: Signal specific part of vm
	generation.
	* generator/InterfaceVM.cs: New class for interface vms.
	* generator/ObjectBase.cs: Parse the class struct.

svn path=/trunk/gtk-sharp/; revision=131604
2009-04-13 17:44:48 +00:00
Mike Kestner
eaa13bdd98 2008-08-27 Mike Kestner <mkestner@novell.com>
* generator/ManagedCallString.cs: use existing Parameters.IsHidden
	method to check for hidden user data. 

svn path=/trunk/gtk-sharp/; revision=111721
2008-08-27 17:18:41 +00:00
Mike Kestner
2d0fc94e2f 2008-08-27 Mike Kestner <mkestner@novell.com>
* generator/ManagedCallString.cs: revert last change.  There are a
	lot of "broken" callback sigs out there which expose user data because
	it's not in the last parameter in the list.  I don't think we can 
	reasonably make a change to hide all those at this point.  This change
	at least hides all the user_data which comes right before a GError 
	param at the end of the list.  I need to follow up with a change which
	handles data parameters in any parameter position, but allows the user
	to mark "exposed" data params for compatibility reasons.
	* generator/Parameters.cs: hide data params which are at the end of a
	list behind an error param.
	* gtk/Gtk.metadata: mark an array parameter on 
	TextBufferDeserializeFunc.

svn path=/trunk/gtk-sharp/; revision=111716
2008-08-27 16:23:32 +00:00
Mike Kestner
568fd5e2a8 2008-08-27 Mike Kestner <mkestner@novell.com>
* generator/ManagedCallString.cs: fixes for data parameter hiding
	in native to managed callback generation.

svn path=/trunk/gtk-sharp/; revision=111706
2008-08-27 13:51:49 +00:00
Mike Kestner
7d611f77e4 2008-07-08 Mike Kestner <mkestner@novell.com>
Patch from Christian Hoff with a few minor tweaks.
	* generator/CallbackGen.cs: refactor to use ManagedCallString
	and drop a ton of redundant, half-baked code.
	* generator/ManagedCallString.cs: add Unconditional setup
	method for stuff that has to happen before the try block.
	Add "drop_first" concept so it can be reused by CallbackGen
	which doesn't drop first params.
	* generator/Signal.cs: use Unconditional method for prep.
	* generator/VirtualMethod.cs: use Unconditional method for prep.
	* gtk/Gtk.metadata: mark a ref param. [Fixes #394352]

svn path=/trunk/gtk-sharp/; revision=107494
2008-07-08 21:12:22 +00:00
Mike Kestner
de56504f8b 2008-03-21 Mike Kestner <mkestner@novell.com>
* bootstrap-2.12: bump svn version
	* generator/CallbackGen.cs: add dnotify support to invoker.
	Store and respond with incoming UserData params. Start using 
	__prefixed private vars to avoid collisions with parameters, 
	like the 'result' params in gio.
	* generator/ManagedCallString.cs: use new data/dnotify invoker
	ctors.
	* generator/MethodBody.cs:
	* generator/Parameters.cs: don't link "out" length params to 
	preceding strings.
	* generator/VMSignature.cs: don't require UserData to be last
	param, since it can have things like error after it.

svn path=/trunk/gtk-sharp/; revision=98782
2008-03-22 01:30:42 +00:00
Mike Kestner
adda8bdcf5 2008-01-29 Mike Kestner <mkestner@novell.com>
* generator/ManagedCallString (Setup): use error param name instead
	of hardcoding error.

svn path=/trunk/gtk-sharp/; revision=94309
2008-01-29 20:04:27 +00:00
Mike Kestner
c93ecb7f88 2007-09-11 Mike Kestner <mkestner@novell.com>
* gtk/Gtk.metadata: virtual_method rules for GInterface generation.
	* generator/ReturnValue.cs (ToNative): new method for the virtual
	method generation.
	* generator/Parameters.cs (FromNative): null guarding.
	* generator/ManagedCallString.cs: rework for interface method
	generation including callback and error param support.
	* generator/CallbackGen.cs: Invoker support. new class that deals
	with persistence of native and wrapper delegates in native to managed
	callback method signatures.
	* generator/VirtualMethod.cs: support for generation of interface
	methods, and all the funky parameters that come with that.
	* generator/InterfaceGen.cs: Fill out the adapter implementation.
	* generator/MethodBody.cs: Initialize overload. Extend ThrowsException
	to support GError outside the last parameter slot.
	* glib/GInterfaceAttribute.cs: New attribute to mark interfaces and
	obtain adapter type.
	* glib/Object.cs (AddInterfaces): interface registration method.
	* glib/GInterfaceAdapter.cs: New abstract class for interface
	adapter generation.
	* glib/Makefile.am: add new files.

svn path=/trunk/gtk-sharp/; revision=85658
2007-09-11 20:34:24 +00:00
Mike Kestner
d8fb820b89 2007-04-20 Mike Kestner <mkestner@novell.com>
* generator/CallbackGen.cs : switch to NativeCallbackSignature.
	* generator/GenBase.cs : add NativeCallbackType member.
	* generator/IGeneratable.cs : add NativeCallbackType member.
	* generator/ManagedCallString.cs : add guarded post call struct
	marshaling back to the native struct.
	* generator/NativeCallbackSignature.cs : new parallel to ImportSignature
	but using NativeCallbackType instead of MarshalType.
	* generator/Signal.cs : switch vm and sig marshaler callbacks to 
	NativeCallbackSignature. Perform guarding post call struct marshaling
	back to the native struct.
	* generator/Parameters.cs : add NativeCallbackType member.
	* generator/SimpleBase.cs : add NativeCallbackType member.
	* generator/StructBase.cs : add NativeCallbackType member using IntPtr
	to support NULL handling.
	* gtk/NodeCellDataFunc.cs : update native marshaler sig.

svn path=/trunk/gtk-sharp/; revision=76011
2007-04-20 15:38:47 +00:00
Dan Winship
eb4fdee774 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 18:45:21 +00:00
Mike Kestner
d3c6721f1e 2005-06-22 Mike Kestner <mkestner@novell.com>
* generator/ManagedCallString.cs : don't assume ref for structs.
	* generator/VMSignature.cs : don't assume ref for structs.

svn path=/trunk/gtk-sharp/; revision=46373
2005-06-22 16:56:52 +00:00
Dan Winship
62258ca7c3 * generator/CallbackGen.cs:
* generator/CodeGenerator.cs: 
        * generator/ManagedCallString.cs:
        * generator/Property.cs: Remove unused vars

        * generator/Method.cs (GetHashCode): have to implement this since
        we're overriding Equals.

        * generator/CallbackGen.cs: print a message when generating a
        broken struct-returning callback. (Currently affects
        GtkSharp.TextSegSplitFuncNative and
        GtkSharp.TextSegCleanupFuncNative)

        * gdk/glue/device.c: 
        * gdk/glue/dragcontext.c: Add missing prototypes

        * gtk/Gtk.metadata: Mark SeparatorToolItem.Draw "new". Re-rename
        CheckMenuItem.Toggled to EmitToggled rather than Toggle, since
        that's a better description of what it does.

        * gtk/CheckMenuItem.custom: implement a "Toggle" method that does
        what the documentation claims it does.

        * gtk/NodeStore.cs: remove unused var

        * gnome/Gnome.metadata: mark DateEdit.Flags, Dialog.Default, and
        PropertyBox.State "new". Hide GnomePixmapEntry.GnomeEntry and
        GnomePixmapEntry.GtkEntry since they do exactly the same thing as
        the methods of the same names inherited from GnomeFileEntry.

        * gnome/glue/canvas-proxy.c:
        * gnome/glue/canvas-proxy.h:
        * gnome/glue/canvas-proxy-marshal.c:
        * gnome/glue/canvas-proxy-marshal.h:
        * gnome/glue/canvas-proxy-marshal.list: Remove unused code

        * gnome/glue/Makefile.am (libgnomesharpglue_2_la_SOURCES): update

        * panelapplet/PanelApplet.metadata: mark PanelApplet.Flags "new"

        * sample/CanvasExample.cs: 
        * sample/CustomCellRenderer.cs: 
        * sample/CustomNotebook.cs: 
        * sample/DrawingSample.cs:
        * sample/Fifteen.cs: 
        * sample/GladeTest.cs: 
        * sample/GtkDemo/DemoHyperText.cs: 
        * sample/GtkDemo/DemoPixbuf.cs: 
        * sample/ScribbleXInput.cs: remove unused vars, use
        GLib.Timeout.Add rather than the deprecated Gtk.Timeout.Add

svn path=/trunk/gtk-sharp/; revision=38043
2004-12-21 18:46:42 +00:00
Dan Winship
faaccd7e0b * generator/ManagedCallString.cs (Setup, Finish, ToString): Add
new methods to allow arbitrary setup and teardown code around the
        managed call. When passing a type with "complicated" marshalling
        requirements as a ref or out param, first assign the value to a
        temporary variable (in Setup), then pass the temp as the ref or
        out param (in ToString), and then assign the new value back to the
        original argument (in Finish).

        * generator/Signal.cs: 
        * generator/SignalHandler.cs: Update to generate correct glue for
        signals with "ref" or "out" params. (#70566)

        * generator/VirtualMethod.cs: Update for ManagedCallString change

        * generator/IGeneratable.cs: add comments explaining what each
        member does

        * gtk/Gtk.metadata: mark Editable.InsertText's "position" arg
        * pass-by-ref

        * sample/Size.cs: connect to the SizeRequested event and override
        it, to test/demo the changes

svn path=/trunk/gtk-sharp/; revision=37854
2004-12-16 23:38:35 +00:00
Mike Kestner
f96454a364 2004-06-25 Mike Kestner <mkestner@ximian.com>
* generator/*.cs : add gpl license blurb and clean up (c)'s.
	* parser/* : ditto
	* doc/*.cs : ditto
	* doc/gen-handlerargs-docs.cs : add little scripty.

svn path=/trunk/gtk-sharp/; revision=30398
2004-06-25 16:35:15 +00:00
Mike Kestner
ba1d3996a4 2003-12-10 Mike Kestner <mkestner@ximian.com>
* generator/CallbackGen.cs : kill ref_owned generation
	* generator/ClassBase.cs : use simple GetObject w/o ref_owned
	* generator/ManagedCallString.cs : new class to generate native
	to managed method calls.
	* generator/Method.cs : kill ref_owned generation
	* generator/MethodBody.cs : kill ref_owned generation
	* generator/Property.cs : kill ref_owned generation
	* generator/Signal.cs : generate delegates and vtable connect
	methods for all signals. Mark VMs with new attr.
	* generator/StructBase.cs : kill ref_owned generation
	* glib/DefaultSignalHandlerAttribute.cs : new attr to mark
	virtual methods.
	* glib/Object.cs : add overload for GetObject that defaults
	to ref_owned=false. Add extern for VM override glue.

svn path=/trunk/gtk-sharp/; revision=21005
2003-12-10 22:56:49 +00:00