Commit graph

488 commits

Author SHA1 Message Date
Stephan Sundermann f978c8f705 GLib.Object: Fixed FindClassProperty
g_object_class_find_property takes a GObjectClass which can be retrieved by
reading an IntPtr from the GObject's Handle
2013-10-11 11:13:08 +02:00
Andrés G. Aragoneses 7d75adf68c glib: fix FindClassProperty()'s copy-paste error
The implementation of FindClassProperty() was the same as the
implementation of FindInterfaceProperty(), both receiving an iface
instead of a GObjectClass* [1].

The reason of this oversight can well be explained by the fact that
FindClassProperty() is private and not used, actually. However, we
may need it soonish as a good bind to g_object_class_find_property.

[1] https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-class-find-property
2013-10-10 20:25:23 +02:00
Stephan Sundermann 53312d5fc0 generator: fixed optional array parameters 2013-10-09 20:35:02 +02:00
Stephan Sundermann b868b80dee glib,generator: map MainContext type and expose members
This is needed to reference a MainContext from
external bindings, which need to create a
MainContext using a Handle
2013-10-09 19:44:50 +02:00
Stephan Sundermann 6ab620d689 generator,glib: added GPollFD and GSource types
GSource type was already there (but was not mapped by
the generator yet) so then the autogenerated methods
have been added manually inside the class after the
custom methods.

Other Source-related class are also generated and added
(but not mapped in the SymbolTable) to glib.
2013-10-09 19:41:21 +02:00
Stephan Sundermann 8b101d5525 glib: Mutex is actually opaque
This means that we're modifying the generated code that
we checked in, so then we increase the future TODO about
more information about what we need to fix later.

The changes to Cond are a consequence of the changes to
Mutex because the former uses the latter.
2013-10-09 18:44:04 +02:00
Stephan Sundermann 9abde602ec glib: add GDate, GDateTime
Add GDate and GDateTime classes to glib, and map
them in the generator's SymbolTable.

(The types TimeZone and TimeVal are also added because
the Date* types depend on them, but there is no need
to map them in the generator.)

Also move the TODOs of other auto-generated classes
to a single TODO in the Makefile
2013-10-09 18:30:10 +02:00
Stephan Sundermann 29a900e51e generator: added conversion for byref structs
The pointer from native is stored inside of a class which
wraps the structure. Fields can be accessed by marshalling
from and to the pointer. glib: Value.Update does now invoke
a private Update() method which is needed to update the new
structures.
2013-10-09 13:40:56 +02:00
Stephan Sundermann 112e2b9598 generator,glib: Added Mutex, RecMutex, Cond types
Bind these types manually and added generator support
for them.
2013-10-09 13:09:34 +02:00
Stephan Sundermann b5806d2a1b generator: fixed string[] return types 2013-10-08 17:54:29 +02:00
Andrés G. Aragoneses f033de7816 glib: reference .NET 3.5's System.Core in MSBuild project
glib.csproj needs to reference System.Core from .NET 3.5 because
glib-sharp now[1] uses System.Action [2] delegate (not to confuse
with System.Action<T>) which was not available in .NET 2.0's System
reference. This way MonoDevelop stops marking "Action" in red color.

[1] 8e07e7d225
[2] http://msdn.microsoft.com/en-us/library/system.action%28v=vs.90%29.aspx
2013-09-24 01:28:08 +02:00
Andrés G. Aragoneses bb0aa9a37c glib: mark MSBuild project with AllowUnsafe setting
In the same way it is needed for other projects such as gtk.csproj.
2013-09-24 01:24:44 +02:00
Andrés G. Aragoneses 872e0edfdd MSBuild: remove AssemblyInfo.cs where it's not present
The only autogenerated AssemblyInfo files are in cairo and in
gtk-sharp's root, not inside other libraries like atk, glib, etc.
Removing them will make MonoDevelop stop rendering a red element
underneath each project.
2013-09-24 01:24:39 +02:00
Andrés G. Aragoneses 9016c304de MSBuild: change some projects to Library type, not Executable
Even though gtk-sharp cannot be built via MSBuild (yet?), it's better
to make the .csproj reflect more closely what you get with the normal
build.
2013-09-24 01:24:33 +02:00
Andrés G. Aragoneses 0312613c32 glib: ObjectManager class can be made static 2013-09-24 01:24:28 +02:00
Andrés G. Aragoneses 234717712e glib: remove unused 'using' statements 2013-09-24 01:24:24 +02:00
Andrés G. Aragoneses 6f16031661 glib: fix NRE regression after interface naming changed
ListBase was throwing a NullReferenceException in DataMarshal() due
to the fact that Reflection was being used to find the adapter name
of the interface generated by the bindings, which has recently
changed [1].

[1] 6cb03440c1
2013-08-24 00:11:05 +02:00
Andrés G. Aragoneses 6d626a24a7 glib: avoid a delegate to be GCed which caused a NRE (bxc#13113)
What seemed to be a race condition (because of not happenning 100% of
the times) ended up being an early garbage collection of a delegate that
was still referenced by an unmanaged struct without having a managed
counterpart [1].

The consequence of this was a NullReferenceException happening in a line
which didn't have a dereference of a null object. The way to reproduce it
deterministically 100% of the times was setting the env var MONO_NO_SMP.

[1] http://www.mono-project.com/Interop_with_Native_Libraries#Memory_Boundaries
2013-07-17 14:24:02 +02:00
Andres G. Aragoneses cb4c7d95ea glib: move some GLib.Object private methods to ClassInitializer class
Refactoring: moving these methods from GLib.Object to ClassInitializer
brings some benefits:
* We can mark OverrideHandlers as private instead of internal.
* We reduce the number of parameters to zero by making them use fields.
* We can make the god GLib.Object class a bit smaller.
* We can make the ClassInitializer.Idx counter private instead of internal.
2013-04-07 08:17:44 +01:00
Andres G. Aragoneses 9ff7ec8b2c glib: install interfaces earlier, override properties in class_init
GObject upstream has started disabling support for installing interfaces
in GTypes after they have already been initialized (class_init) [1], so
we need to add GInterfaces a bit earlier (*before* class_init starts).

As GLib.Object.OverrideProperty() cannot to be called before class_init
(because it receives a GObjectClass, not a GType) or after (because
otherwise class_init would complain about properties of an interface not
being defined), then we need to call it during class_init.

[1] http://bugzilla.gnome.org/687659

A good side-effect of this fix is that we no longer use the hacky uint
field 'idx' to track the properties count for each class; now it gets
moved to the ClassInitializer class, and thus can be non-static, which
makes a bit more sense (we leave the old OverrideProperty overload for
backwards compatibility).

Simplest way to test this is launching the sample/treemodeldemo.exe and
sample/custom-scrollable.exe in Ubuntu 13.04 beta (which has GLib 2.36).
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=11510
2013-04-07 07:51:30 +01:00
Andres G. Aragoneses 88bb31bfa7 glib: Use GTHREAD preprocessor flag with old versions of glib
We switch the logic from DISABLE_GTHREAD_CHECK to ENABLE_GTHREAD_INIT
to make the define clearer, and so that it is actually needed when using
older versions of glib, not newer.

Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
2013-03-24 11:37:22 +01:00
Bertrand Lorentz ab61fbccbd glib: Fix crash when freeing lists with elements typed as interfaces
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.
2012-11-18 16:06:34 +01:00
Bertrand Lorentz 306f422c38 Fix a crash during initialization of interfaces (bxc#8447)
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.
2012-11-17 17:34:50 +01:00
Bertrand Lorentz 499540dd6d glib: Add GIOCondition symbol to glib-api.xml
This fixes some generator warnings for gio.
2012-11-11 11:46:40 +01:00
Rickard Edström 8e07e7d225 Add a SynchronizationContext implementation for GLib (bnc#621444)
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>
2012-11-08 22:33:46 +01:00
Bertrand Lorentz df751f87ce glib: Switch to generic collections in Marshaller and ValueArray 2012-11-04 16:58:49 +01:00
Bertrand Lorentz 6e3e73e2ac glib: Use dictionaries to store type information in GType class
Yay, type safety when managing types...
2012-11-04 16:58:49 +01:00
Bertrand Lorentz 60612071c1 Add a MonoDevelop solution and projects for browsing the codebase
This is just to be able to use MonoDevelop to browse the codebase, both
custom and generated code. It is NOT intended to be used to build
anything.
2012-10-13 16:44:10 +02:00
Andrés G. Aragoneses 61b67120c2 glib: add missing lock statements for Objects collection
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>
2012-10-13 15:54:50 +02:00
Michael Hutchinson d686a4d6aa Added Object.TryGetObject that gets wrapper only if already surfaced 2012-10-13 15:06:51 +02:00
Andrés G. Aragoneses 85b84f99f6 glib: Remove redundant call to ToggleRef.QueueUnref()
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.
2012-05-08 20:35:36 +01:00
Andres G. Aragoneses b008a626f8 glib: don't modify Makefile.am
The new -define flag DISABLE_GTHREAD_CHECK can be added at configure time to already existing $CSFLAGS, as Mike Kestner pointed out.
2012-05-04 22:20:14 +01:00
Andres G. Aragoneses 3862bc75ec glib: do not call g_thread_ functions in GLib >= 2.31
Based on downstream patch by by Christopher James Halse Rogers <raof@ubuntu.com>
Should fix BXC#2329 reported by Sergey Litvinov.
2012-05-03 23:45:07 +01:00
Mike Kestner 0e0d0ec94d Don't release const strings in GLib.Global. 2012-04-21 17:38:10 -05:00
Mike Kestner b107fdd7c0 Improve MissingCtorException message. 2012-03-28 22:10:47 -05:00
Mike Kestner 1ec86832dd Remove empty file. 2012-03-28 22:10:47 -05:00
Bertrand Lorentz 0de6e9869d ParamSpec: Add override modifier to the ToString method
This remove a compilation warning.
2011-12-03 16:41:21 +01:00
Bertrand Lorentz d239b5cc4e Object: Remove some trailing whitespace, no real code change 2011-12-03 16:41:17 +01:00
Bertrand Lorentz 91dda7f5be Object: Fix registration of inherited interface properties
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.
2011-12-03 16:41:16 +01:00
Andres G. Aragoneses 1215ebc770 Object: Use the type as top-level key for properties hash
Types could use same param_spec object so their PropertyInfo
objects shouldn't be mixed, otherwise we could get type
mismatch errors like the one in:

http://mail.gnome.org/archives/banshee-list/2011-November/msg00141.html

This should be the final part of:
https://bugzilla.novell.com/show_bug.cgi?id=442068
2011-12-03 16:39:05 +01:00
Mike Kestner 9d319c8033 Merge pull request #26 from dufoli/master
ginterface properties support
2011-11-20 21:42:02 -08:00
Olivier Dufour 37d15305a3 GInterface: Add properties support 2011-11-20 19:41:56 +01:00
Mike Kestner 6fbd419c1d Remove source delegates by id.
* glib/Idle.cs: use g_source_remove and id in Remove(Delegate)
* glib/Timeout.cs: use g_source_remove and id in Remove(Delegate)
[Fixes #632765]
2011-10-13 05:23:39 -05:00
Bertrand Lorentz 18d1af6907 build: Specify assembly version when uninstalling from the GAC
We need to qualify the assembly name with the version, otherwise gacutil
uninstall all versions of the assembly.
Fixes http://bugzilla.xamarin.com/show_bug.cgi?id=207
2011-08-11 18:44:58 +02:00
Mike Kestner 4f42fb77fb Improve ToggleRef release overhead.
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.
2011-07-29 13:37:39 -05:00
Andres G. Aragoneses 228a2b3da4 glib: Fix calling to Free() twice for the same ToggleRef
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.
2011-07-29 18:21:27 +01:00
Mike Kestner 51d5faf651 Mark calling convention on GInterface callbacks
Fixes #583901.  Adapted from fix for 2.12 from Markus Henschel.

* glib/GInterfaceAdapter.cs: add UnmanagedFunctionPointer attrs
2011-07-24 18:29:04 -05:00
Bertrand Lorentz 680dd23965 Handle floating refs in InitiallyUnowned
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.
2011-06-11 19:08:21 +02: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
Mike Kestner 2e115e2aff * glib/Value.cs: revert to "working" GValue layout from 2-12 branch.
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.
2011-04-27 19:05:11 -05:00