When a C function returns an array, we need to be able to determine its
length. This is done either through a parameter to that function, or
because the array is null-terminated. If we don't know about either of
those, we print out a warning and fail the validation for the return
value. This means the corresponding method will not be generated.
This fixes a crash when trying to generate a method for which this
information is missing.
This wasn't a problem until now because the parser doesn't handle array
return values, so they were always handled through fix-ups. But now we
can get a GAPI XML converted from GIR which contains the "array"
attribute for a return value but no other information.
In a lot of places, we were only checking the presence of boolean
attributes, like "array", automatically assuming they were true. This
meant that we didn't allow setting them explicitly to false, which
apparently is needed for some bindings.
For all boolean attributes, we now use the GetAttributeAsBoolean method
added in the previous commit, to correctly check the value of the
attribute. As before, if the attribute is not present, it is considered
to be false.
Thanks to Stephan Sundermann for noticing this issue.
* 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.
* cairo/Context.cs: add ctor (IntPtr, bool owned)
* cairo/cairo-api.xml: expose cairo_t as new ownable symbol type
* generator/HandleBase.cs: implement IOwnable
* generator/IOwnable.cs: new interface for wrapping ownable types
* generator/Makefile.am: add new files to build
* generator/OwnableGen.cs: SimpleBase subclass to expose IOwnable
* generator/Parameters.cs: use IOwnable.FromNative instead of HandleBase
* generator/Parser.cs: parse ownable symbol type
* generator/ReturnValue.cs: use IOwnable.FromNative instead of HandleBase
* generator/*.cs: Add a LogWriter class which formats warnings
consistently on the console. Supports the concept of non-fatal
validation warnings, since it doesn't rely on the unrolling of the
validation stack to associate a warning to a given type.
Main purpose was to add a non-fatal warning for missing element_type
attributes on list return values, though it results in cleaner log
output, and also updates some warning messages to be more helpful in
how to resolve them.
* generator/ReturnValue.cs: support metadata override of default return
values. Based on a patch from Sebastian Dröge. [Fixes#541299]
svn path=/trunk/gtk-sharp/; revision=142516
* 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
* generator/ReturnValue.cs: null-term array marshaling for vms.
* generator/VirtualMethod.cs: use ToNative return type in native
callbacks.
[Fixes#501294] Patch by Sebastian Dröge.
svn path=/trunk/gtk-sharp/; revision=133670
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
* generator/ReturnValue.cs: map gfilename* list elements to type
ListBase.FilenameString so they are marshaled correctly.
* glib/Marshaller.cs: handle FilenameStrings in ListPtrToArray.
* gtk/Gtk.metadata: FileChooser.GetFilenames and ListShortcutFolders
return type mangling to avoid custom implementations.
* gtk/FileChooser*.custom: kill manual Filenames and ShortcutFolders.
svn path=/trunk/gtk-sharp/; revision=122802
* generator/ReturnValue.cs: use new ListPtrToArray marshaler for
lists with known element types.
* glib/Marshaller.cs: new ListPtrToArray marshaller with more
aggressive list disposal.
* gtk/Container.custom: remove manual Children impl. Use Children
in GetEnumerator instead of pinvoking directly.
* gtk/Gtk.metadata: remove hidden attr and add element type and owned
for Container.GetChildren to generate it properly.
svn path=/trunk/gtk-sharp/; revision=111173
* generator/ReturnValue.cs: use new GLib.Opaque.OwnedCopy for owned
opaque return values.
* glib/Opaque.cs: introduce OwnedCopy property to support returning
owned opaque instances from native to managed callbacks.
[Fixes#374641]
svn path=/trunk/gtk-sharp/; revision=100762
* atk/Atk.metadata: markup all the Ref* methods to indicate owned refs.
* generator/ReturnValue.cs: Add owned object ToNative handling.
* generator/VirtualMethod.cs: Split ToNative call from managed method
invocation to avoid duplicate calls in null checking scenarios.
* glib/Object.cs: add OwnedHandle property for use by language binding
code which needs to pass owned refs to native methods.
svn path=/trunk/gtk-sharp/; revision=99849
* generator/*.cs: implement the interfaces on the adapters too.
Generate an Implementor interface for users which exposes the
methods to implement. Register based on the Implementor sub-iface.
* gtk/*Adapter.custom: custom implementations for the custom
interface members.
* gtk/TreeIter.custom: make UserData public.
* sample/TreeModelDemo.cs: sample for implementing a TreeModel
interface.
svn path=/trunk/gtk-sharp/; revision=86753
* 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
* 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
* generator/ReturnValue.cs : support owned and elements_owned for lists.
* glib/List.cs : add ctor overloads for memory mgmt.
* glib/ListBase.cs : add ctor overloads for memory mgmt. Dispose
elements if specified.
* glib/SList.cs : add ctor overloads for memory mgmt.
* gnome/Gnome.metadata : unhide and generate a List prop.
* gnomevfs/Gnomevfs.metadata : unhide and generate a List prop.
* gtk/FileChooser.custom : new. add hidden props.
* gtk/FileChooserButton.custom : new. impl hidden props.
* gtk/FileChooserDialog.custom : remove some List props and use the
GLib.Marshaller for the remaining ones..
* gtk/FileChooserWidget.custom : remove some List props and use the
GLib.Marshaller for the remaining ones..
* gtk/Gtk.metadata : unhide and let the generator do some List props.
svn path=/trunk/gtk-sharp/; revision=46457
* generator/ReturnValue.cs : don't write a sem in FromNative.
* glib/ListBase.cs : handle GLib.Object explicit element types.
* glib/Marshaler.cs : only copy lists if Count > 0.
* gtk/Gtk.metadata : unhide Window.ListToplevels with a proper element
type for automatic list to array marshaling.
* gtk/Window.custom : kill manual ListToplevels impl.
svn path=/trunk/gtk-sharp/; revision=45654
end with "callback, gpointer, GDestroyNotify", then mark the
callback as having "notified" Scope.
(Parameters.IsHidden): Hide user_data and GDestroyNotify after a
callback.
(Parameter.Scope): make this settable
(Parameter.IsDestroyNotify): new test
* generator/MethodBody.cs (Initialize): Handle "notified" callback
scope (using a GCHandle and GLib.DestroyHelper.NotifyHandler)
* generator/CallbackGen.cs (GenWrapper): Add a static
"GetManagedDelegate" method to the wrapper type, to translate a
native delegate back to its corresponding managed delegate.
(FromNative): use GetManagedDelegate.
* generator/ReturnValue.cs (Validate): We handle callback return
values now
* generator/SymbolTable.cs: marshal GDestroyNotify as
GLib.DestroyNotify
* glib/DestroyNotify.cs: Moved from gtk
* gtk/Gtk.metadata: globally change GtkDestroyNotify to
GDestroyNotify, but then change back the ones that are exposed in
the API. Un-hide lots of methods we can correctly autogenerate
now.
* gtk/DestroyHelper.cs: moved to glib
* gtk/*.custom: remove methods that are autogenerated now, add
Obsolete wrappers where needed, replace Gtk.DestroyHelper usage
with GLib.DestroyHelper.
* gdk/Gdk.metadata:
* gnome/Gnome.metadata: Turn Gdk.Drawable.SetData and
Gnome.IconList.SetIconDataFull's GDestroyNotify args into
gpointers so the generated API stays the same as it used to be.
* rsvg/Handle.custom: implement deprecated SetSizeCallback
* sample/GtkDemo/DemoIconView.cs (CreateSort): update for API
changes
svn path=/trunk/gtk-sharp/; revision=44020
* generator/MethodBody.cs : remove an unused var.
* generator/ReturnValue.cs : privatize a couple props. Refactor the
SymbolTable lookup logic to be generatable based.
svn path=/trunk/gtk-sharp/; revision=41528
* generator/ReturnValue.cs : use ToNativeReturnType for ToNativeType
instead of MarshalType.
* generator/Signal.cs : deal with boxed return values. beef up return
handling in the default handler generation code.
* generator/SignalHandler.cs : use ToNative return types for native
callbacks. Remove redundant casting/conversion in callback impl.
[Fixes#71899]
svn path=/trunk/gtk-sharp/; revision=39724