If a GList or a GSList had its element type set to a GInterface, and if
the elements were marked as owned, it would end up freeing those
elements with g_free(), which would lead to a crash.
They need to be unreffed with g_object_unref, but the criteria for that
was whether the element type is assignable to GLib.Object. This is not
true for GInterface types.
We now first check if the element type is an opaque. If not, and if it's
assignable to GLib.IWrapper, we then use g_object_unref.
From what I can see, all GLib.IWrapper subclasses that not opaque can be
unreffed with g_object_unref.
GInterfaceInfo.Data was automatically set to be a GCHandle on the
interface adapter. But the generated GInterfaceInitHandlers were
not using it, just free'ing it.
But for the GInterface property support, the Data field is now used to
pass the class pointer, so casting it to a GCHandle to free it would
cause an exception.
We now don't assume anything about GInterfaceInfo.Data.
Create a GLibSynchronizationContext that sends code to be run on the
GLib main loop, and set it as the current SynchronizationContext in
Gtk.Init().
When you use the await keyword to do a task asynchronously, by default
the awaiter will capture the current SynchronizationContext, and if
there was one, when the task completes it’ll Post the supplied
continuation back to that context, rather than running it on whatever
thread it wants.
This means that if you use the async/await keywords in your Gtk# app,
things will now work as expected with the GTK main thread. For example:
static async void DoWork () // called in the GTK main thread
{
// Do some stuff with the UI...
label.Text = "Starting Work";
// Run something asynchronously, UI is not frozen
int res = await DoLongOperation ();
// Do some more UI stuff, it'll run on the GTK main thread
label.Text = "Work done";
}
Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
When accessing the static Objects collection in GLib.Object
class, a lock was held in some places but not all of them.
Brought up by Alan McGovern.
Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
In slow systems this redundant call was causing the following CRITICAL:
GLib-GObject-CRITICAL **: g_object_remove_toggle_ref:
assertion `G_IS_OBJECT (object)' failed
The GLib.Object.Dispose(bool) method already calls this function at the
end so there is no need to check for duplicates in the PendingDestroys
static field of ToggleRef class (thanks to Alan McGorvern for helping
tracking down the root cause), the double unref call is just prevented.
Fixes BXC#4909.
We need to add inherited interface properties in the Properties hash, so
we remove the DeclaredOnly flag when looking for interface properties in
the type.
We also need to use the type itself as the hash key, and not the adapter
type.
Candidate patch provided by Andres in pull request #17.
* glib/Object.cs: use ToggleRef.Dispose.
* glib/ToggleRef.cs: implement IDisposable and expose former Free
functionality as Dispose(). Free is now private non-lock taking
called by Dispose and the idle queue handler.
Apparently the recent changes in gtk-sharp master that changed
the destroy/dispose strategy caused a bug about calling
g_object_remove_toggle_ref() twice because now Dispose(true)
could call ToggleRef.Free() directly bypassing
ToggleRef.QueueUnref(). This change makes sure that
the ref is removed from the PendingDestroys list.
When Gtk.Object was removed, most of the code was moved to Gtk.Widget.
But the part that deals with floating references actually belongs in
Glib.InitiallyUnowned.
This fixes various issues, in particular crashes in the TreeModelDemo
sample.
* 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.
The replaced code fails because sizeof(GValue) is 20 on 32 bit
linux but Marshal.SizeOf(GLib.Value) reported 24. If it aint broke,
don't fix it, and the long works on 32 and 64 in 2.12 and earlier.
* glib/Object.cs: move finalization queue to ToggleRef and make
Dispose() non-virtual with a protected virtual Dispose(bool).
Also added a WarnOnFinalize static property to produce nags for
undisposed objects.
* glib/ToggleRef.cs: add finalization queue and QueueUnref method.
* gtk/NodeStore.cs: override Dispose(bool)
* gtk/Widget.custom: override Dispose(bool)
* gdk/Display.custom: rework signal connection
* gdk/Window.custom: rework signal connection
* generator/Signal.cs: generate for new API.
* glib/Object.cs: add (Add|Remove)SignalHandler methods and use
them for the Notify connections. Move to generic collections for
everything but the Data hash.
* glib/Signal.cs: kill Lookup methods and add delegate fields
* glib/ToggleRef.cs: remove Signals hash, it doesn't belong here.
* gtk/Clipboard.custom: rework signal connection
* gtk/ListStore.custom: rework signal connection
* gtk/TextView.custom: remove obsolete signal
* gtk/TreeModelAdapter.custom: rework signal connection
* gtk/TreeModelFilter.custom: rework signal connection
* gtk/TreeModelSort.custom: rework signal connection
* gtk/TreeStore.custom: rework signal connection
* gtk/Widget.custom: rework signal connection
* gtk/Window.custom: remove obsolete signal
* glib/Object.cs: don't bother with IsAlive check on tref
* glib/Signal.cs: remove unnecessary as usage
* glib/ToggleRef.cs: make Signals a generic dictionary
* glib/GType.cs:
* glib/Makefile.am:
* glib/Object.cs:
* glib/ParamSpec.cs:
* glib/PtrArray.cs:
* glib/SignalClosure.cs:
* glib/Value.cs:
mark private struct fields public to avoid 0169, and remove the nowarn
from the csc command. fixed one real warning, exposed a bunch of
obsolete usage still to fix.
* generator/SymbolTable.cs : add GVariant type mapping.
* glib/Variant.cs: initial implementation of an opaque class to expose
the GVariant type from glib. We won't make any attempt to combine managed
references since there is no "toggle" ref capability. We'll do a one-to-one
ref_sink/unref pair on construction/dispose.
* AssemblyInfo.cs.in: kill keyfile attr
* Makefile.am: moved mono.snk to cairo dir
* Makefile.include: no need to copy snk into builddir any longer.
* cairo/AssemblyInfo.cs: kill keyfile attr
* cairo/Makefile.am: snk relocated into here. use it directly.
* glib/Makefile.am: no need to copy snk into builddir any longer.
* gtkdotnet/Makefile.am: no need to copy snk into builddir any longer.