Commit Graph

123 Commits

Author SHA1 Message Date
Martin Pitt
ed1e3816ad gobject-2.0: Annotate another GSignal function taking instances
As a followup to commit a72983a, annotate g_signal_handlers_destroy() as well.
2013-09-02 12:04:43 +02:00
Emmanuele Bassi
a72983a5db gobject-2.0: Annotate GSignal functions taking instances
Unbreak the GSignal API at least for GObject sub-classes.

https://bugzilla.gnome.org/show_bug.cgi?id=685387
2013-09-02 08:25:56 +02:00
Matthias Clasen
90da4ed628 Trivial typo fix 2013-07-28 22:06:57 -04:00
Ryan Lortie
3d1d49177b gsignal: remove some pointless locking
We previously hold a lock in the loop that collects the arguments for
g_signal_emit(), which we drop before calling into the argument
collection functions and reacquire again at the bottom of the loop (ie:
one release/acquire pair for each argument collected).  To make matters
worse, the lock is just released again after the loop.

Presumably that was done to protect the access to the parameter array,
but it's pretty unlikely that this is needed because the only way it
changes is if the signal is unloaded.  That only happens when unloading
types which is quite unlikely to happen while we are emitting on an
instance of that type (and, as an aside, never happens anymore anyway).

If we move the unlock below the loop up above it and remove the
acquire/release pair from the loop, we improve performance in the new
arg-collecting performance tests by ~15% (more like ~18% in the case
where we only emit to one handler -- where argument collection dominates
more).

https://bugzilla.gnome.org/show_bug.cgi?id=694380
2013-05-23 21:50:54 -04:00
Dan Winship
4b94c0831e Use 'dumb quotes' rather than `really dumb quotes'
Back in the far-off twentieth century, it was normal on unix
workstations for U+0060 GRAVE ACCENT to be drawn as "‛" and for U+0027
APOSTROPHE to be drawn as "’". This led to the convention of using
them as poor-man's ‛smart quotes’ in ASCII-only text.

However, "'" is now universally drawn as a vertical line, and "`" at a
45-degree angle, making them an `odd couple' when used together.

Unfortunately, there are lots of very old strings in glib, and also
lots of new strings in which people have kept up the old tradition,
perhaps entirely unaware that it used to not look stupid.

Fix this by just using 'dumb quotes' everywhere.

https://bugzilla.gnome.org/show_bug.cgi?id=700746
2013-05-21 11:23:22 -03:00
Ryan Lortie
f5d40bd813 gsignal: improve warning output
When looking up signals by name (to connect, for example) and the named
signal cannot be found on the given instance, report the type of the
instance.

This is quite a lot more useful as a diagnostic message than only a
memory address.

https://bugzilla.gnome.org/show_bug.cgi?id=694350
2013-02-22 00:54:50 +00:00
Alexander Larsson
aede774642 signals: Ensure we ref handler in emission fast path
We need to keep a reference to the handler in the fast path, just like
in the slow path, otherwise if another thread disconnects the handler
we may destroy the closure while we're using it without the lock held.

We also move the freeing of the instance to after the emission is totally
done as the handler_unref_R (and the tracepoint) reference it.

https://bugzilla.gnome.org/show_bug.cgi?id=694253
2013-02-21 16:54:44 +01:00
Alexander Larsson
3e274423ba signals: No need to use atomics for Handler refcount
handler_ref and handler_unref_R are always called with the signal
lock held. This is obvious for handler_unref_R as it even sometimes
drops this lock, and can be verified quickly for handler_ref by looking
at all call sites.

This improves the performace about 6% on the emit-handled and the
emit-handled-generic tests.

https://bugzilla.gnome.org/show_bug.cgi?id=694253
2013-02-21 16:54:44 +01:00
Ryan Lortie
d89fb7bf10 gsignal: fix closure invalidation code
This is the bug that has been causing segfaults and criticals when accel
keys are used to close windows via GtkUIManager.

The main cause of this problem was a mistake made in the original patch
when modifying the handler_lookup() to take the extra 'closure'
parameter.  The original check used was:

    if (handler->sequential_number == handler_id ||
       (closure && handler->closure == closure))

It was called to find a particular closure like so:

    handler_lookup (instance, 0, closure, &signal_id);

The problem is that the check will return if either the signal ID or
closure matches (if a closure was given).  The calling code assumes 0 to
be an invalid signal ID which will match no handlers, but unfortunately
the rest of gsignal code uses this to denote a signal that has already
been disconnected.  The result is that this function was searching for a
matching closure _or_ the first already-disconnected handler.  When it
found the already-disconnected handler, we'd get criticals and crashes.

The condition has been corrected; it now ignores the handler_id
parameter if the closure parameter is non-NULL.

While we're in here, change the lifecycle of the invalidation notify to
be easier to understand.

Before, the notify was removed when the last reference on the handler
dropped.  This could happen in very many situations; often at the end of
an emission.  Instead, we now tie the registration of the notifier to
the lifecycle of the signal connection.  When the signal is disconnected
we remove the notification, even if other references are held (eg:
because it is currently being dispatched).

https://bugzilla.gnome.org/show_bug.cgi?id=690118
2013-01-16 23:04:11 -05:00
Ryan Lortie
a36028f386 gsignal: really fix closure invalidation
Commit 66b0d95f0b missed this part of the
patch.
2012-10-13 12:16:32 -04:00
Ryan Lortie
c15769d304 [gsignal] fix up a crasher in previous commit
The previous commit introduced a new variable in the Handler struct but
didn't initialise it.  This was causing some tests to crash.

https://bugzilla.gnome.org/show_bug.cgi?id=118536
2012-10-08 11:21:58 -04:00
Matthias Clasen
d03d26feab [gsignal] disconnect invalidated closures
Modify gsignal to automatically disconnect a GClosure that becomes
invalid (in the g_closure_invalidate() sense).

Previously, when g_signal_connect_object() was used with a GObject as
the user_data and that object was destroyed, the handler would no longer
be called but the signal handler was itself was not disconnected (ie:
the bookkeeping data was kept around).

The main effect of this patch is that these signal handlers will now
be automatically disconnected (and fully freed).

The documentation for g_signal_connect_object() has anticipated this
change for over 10 years and has advised the following workaround when
disconnecting signal handlers connected with g_signal_connect_object():

 if (g_signal_handler_is_connected (instance, id))
   g_signal_handler_disconnect (instance, id);

If your code follows this practice then it will continue to work.

If your code never disconnects the signal handler then it was wasting
memory before (and this commit fixes that).

If your code unconditionally disconnects the signal handler then you
will start to see (harmless) g_critical() warnings about this and you
should fix them.

https://bugzilla.gnome.org/show_bug.cgi?id=118536
2012-10-08 11:21:48 -04:00
Colin Walters
56411bb678 gsignal: Properly handle NULL nodes 2012-06-22 10:32:25 -04:00
Mike Gorse
53b1afba0e Invalidate single_va_closure when adding an emission hook
If the optimization is used for only having one closure handling a
signal emission, then hooks will not be run, so it should be disabled
when an emission hook is added.

https://bugzilla.gnome.org/show_bug.cgi?id=671918
2012-03-14 06:01:36 -04:00
Alexander Larsson
cb44e96dfa Fix crash in signal emission optimization
The trace of the signal emission of the was calculating the instance
type after the instance was unrefed. Fix this by keeping the instance type around.
2012-03-09 11:32:45 +01:00
Alexander Larsson
bbe4b57195 signal emission: Allocate instance_and_param with alloca
This Gives a 5% performance increase in e.g. the emit-handled test.
2012-03-09 09:57:03 +01:00
Emmanuele Bassi
75ca1cd158 gobject: Fix a compiler warning
Shuffle the parenthesis around.
2012-03-07 12:53:14 +00:00
Alexander Larsson
026340c5fc Fix unused variable warning 2012-03-06 11:35:17 +01:00
Matthias Clasen
afe30b2884 Fix a compiler warning 2012-03-05 07:54:47 -05:00
Alexander Larsson
2d6502f67b fastpath: Do allow NO_RECURSE fastpath for NOP emissions
This fixes a performance regression wrt the old NOP emission
handler.
2012-03-03 21:36:10 +01:00
Alexander Larsson
b05ea89d0c Mask out G_SIGNAL_TYPE_STATIC_SCOPE when comparing types 2012-03-02 20:22:29 +01:00
Alexander Larsson
f02ec2f2de Optimize single-handler va_marshaller case
When there is only one closure handling a signal emission and
it doesn't have a bunch of complicated features enabled we
can short circuit the va_args collection into GValues and call the
callback via the va_marshaller directly.

https://bugzilla.gnome.org/show_bug.cgi?id=661140
2012-03-02 17:13:03 +01:00
Alexander Larsson
a3e91088ce Use builtin marshallers and va_marshallers if possible
If the signal argumment types matches a built in standard
marshaller we use the va_marshaller for that, and also the
normal marshaller if NULL was specified (as its faster than
the generic one).
2012-03-02 17:13:03 +01:00
Alexander Larsson
7964cda8e6 Add g_signal_set_va_marshaller
This lets you set a va_marshaller on your signal which will be
propagated to all closures for the signal. Also, automatically
uses the generica va_marshaller if you specify a NULL c_marshaller.

https://bugzilla.gnome.org/show_bug.cgi?id=661140
2012-03-02 17:13:03 +01:00
Alexander Larsson
d5fbbe400a Add GRealClosure and move meta_marshallers there
This means we're not abusing the notifiers for meta_marshallres,
and we're able to later cleanly add other fields to GClosure.

We still have to leave the ABI intact for the GClosure->meta_marshal
bit, as old G_CLOSURE_N_NOTIFIERS macro instances still accesses it.
However, we always set it to zero to keep those macros working.

https://bugzilla.gnome.org/show_bug.cgi?id=661140
2012-03-02 17:13:03 +01:00
Marc-André Lureau
fb95c20c96 Add G_SIGNAL_DEPRECATED
Similar to G_PARAM_DEPRECATED. It will warn only for users of the
signals, so a signal can still be emited without warning, for
compatibility reasons.

Apparently, there is no way user flags could have been used before,
so that shouldn't break anyone.

https://bugzilla.gnome.org/show_bug.cgi?id=663581
2011-11-07 23:12:45 +01:00
Javier Jardón
108480b7ba gobject: Use G_VALUE_INIT 2011-10-18 17:12:33 +01:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Pavel Holejsovsky
fd1a12ca4d [gi] Add signal annotations 2011-08-21 17:17:07 +02:00
Matthias Clasen
f5472ed232 Trivial typo fix 2011-08-13 13:53:48 -04:00
Matthias Clasen
9bcf89cd70 Document libffi as new dependency 2011-08-08 23:16:07 +02:00
Johan Dahlin
fa2861e3b6 Use a generic marshaller if one is not specified
Since g_cclosure_marshal_generic is always enabled, it makes
sense to always use that instead of using generated ones.

https://bugzilla.gnome.org/show_bug.cgi?id=654917
2011-07-19 14:38:34 -03:00
Colin Walters
b74e2a720a Stop using glib-genmarshal at build time
To help cross compilation, don't use glib-genmarshal in our
build.  This is easy now that we have g_cclosure_marshal_generic().

In gobject/, add gmarshal.[ch] to git (making the existing entry
points stubs).

In gio/, simply switch to using g_cclosure_marshal_generic().

https://bugzilla.gnome.org/show_bug.cgi?id=652168
2011-06-20 17:24:07 -04:00
Ryan Lortie
8073759f8c Remove all uses of G_CONST_RETURN
Just use 'const'.

https://bugzilla.gnome.org/show_bug.cgi?id=644611
2011-06-09 11:15:40 -04:00
Colin Walters
3bd3067ffc gobject: Use _ prefixing in private headers over G_GNUC_INTERNAL in public headers
This helps out gtk-doc and g-ir-scanner, and also makes much clearer
what's private versus public.

https://bugzilla.gnome.org/show_bug.cgi?id=651745
2011-06-03 12:40:01 -04:00
Emmanuele Bassi
08f0a31289 Revert "Remove all uses of G_CONST_RETURN"
This reverts commit 36741245cc.

The removal has not been discussed, except on Bugzilla:

https://bugzilla.gnome.org/show_bug.cgi?id=644611
2011-03-15 09:03:28 +00:00
Ryan Lortie
36741245cc Remove all uses of G_CONST_RETURN
Just use 'const'.
2011-03-15 01:32:22 -04:00
Christian Persch
61b0e1c8d4 Add G_SIGNAL_MUST_COLLECT
In some cases, signal arguments have to be collected, even if there are i
no signal handlers connected (e.g. for GVariant parameters, where collection
consumes a floating variant).

Based on a patch by Christian Persch.

Bug #643624.
2011-03-15 01:32:22 -04:00
Ryan Lortie
3c808dc874 GSignal: fix trivial docs typo 2010-10-12 21:34:26 -04:00
Ryan Lortie
15d87c2cc4 GObject: add g_signal_accumulator_first_wins
Deals with the case where we want exactly one signal handler to run.
2010-10-12 21:34:17 -04:00
Ryan Lortie
0fc50fa5f7 gobject/: fully remove gobjectalias hacks 2010-07-07 19:40:48 -04:00
Alexander Larsson
8e41be13ef Add dtrace and systemtap support for gobject
This adds static markers and systemtap tapsets for:

* type creation
* object lifetimes (creation, ref, unref, dispose, finalize)
* signal creation and emission

Signal emissions and finalization marker have a corresponding
*_end (or *-end in dtrace) version that is when the corresponding
operation is finished.

https://bugzilla.gnome.org/show_bug.cgi?id=606044
2010-05-27 14:51:41 -04:00
Stefan Kost
3d98c449b1 gsignal: improve g_signal_new docs.
Using 0 for class_offset is only a means to be able to add signal when running
out of slots in the lass structure.
2010-03-06 14:15:25 +02:00
Benjamin Otte
914120b970 Ensure values are memset to 0 when calling G_VALUE_COLLECT_INIT()
The reason we need to enforce this is that the GTypeValueTable
documentation explicitly states that memory is memset to 0 when the
value_init function is called.

https://bugzilla.gnome.org/show_bug.cgi?id=603590
2010-01-18 14:46:55 +01:00
Edward Hervey
0f25115ffc gsignal: Use new G_VALUE_COLLECT_INIT variant
Makes g_signal_emit_valist from 15% to 20% faster.

Results reported from profiling the pan newsreader which uses a variant
of simple and complex signal emissions (i.e no args or various args)

https://bugzilla.gnome.org/show_bug.cgi?id=603590
2010-01-13 10:16:48 +01:00
Kristian Rietveld
622f010120 when defaulting to the only item in the array, check if this is indeed the
2009-03-13  Kristian Rietveld  <kris@imendio.com>

	* gsignal.c (signal_lookup_closure): when defaulting to the only
	item in the array, check if this is indeed the default closure.
	(patch by Tim Janik).


svn path=/trunk/; revision=7979
2009-03-13 09:22:57 +00:00
Matthias Clasen
db830dd381 Fix some documentation typos
svn path=/trunk/; revision=7707
2008-11-28 23:53:13 +00:00
Dan Winship
7afe2bb07a add uint* -> int* casts in g_atomic_int calls to avoid gcc warnings
* gobject.c (g_object_ref, g_object_unref)
	(g_object_freeze_notify, g_object_notify, g_object_thaw_notify):
	* gparam.c (g_param_spec_ref, g_param_spec_unref):
	* gsignal.c (handler_ref, handler_unref_R): add uint* -> int*
	casts in g_atomic_int calls to avoid gcc warnings

svn path=/trunk/; revision=7551
2008-09-26 16:00:33 +00:00
Michael Natterer
864fbce267 Reviewed by Tim Janik:
2008-07-21  Michael Natterer  <mitch@imendio.com>

	Reviewed by Tim Janik:

	* gsignal.c (g_signal_chain_from_overridden_handler): allocate
	the temp GValue array with GSLice.

	(g_signal_emit_valist): dito. Remove optimization/obfuscation of
	allocating up to 16 GValues on the stack and always use GSLice.


svn path=/trunk/; revision=7229
2008-07-21 10:36:03 +00:00
Michael Natterer
20d4f6da73 Bug 541208 – Functions to easily install and use signals without class
2008-07-04  Michael Natterer  <mitch@imendio.com>

	Bug 541208 – Functions to easily install and use signals without
	class struct slot

	* gobject.symbols
	* gsignal.[ch] (g_signal_new_class_handler): the same as
	_gtk_binding_signal_new(), to install signals with a callback
	instead of a class struct slot as class closure.

	The next two functions are C convenience and much easier to use
	than the generic overriding and chaining APIs which are intended
	primarily for language bindings:

	(g_signal_override_class_handler): to override a signal with a
	callback instead of a class struct slot.

	(g_signal_chain_from_overridden_handler): to chain up from a
	signal without class struct slot. The API is similar to
	g_signal_emit().


svn path=/trunk/; revision=7157
2008-07-04 11:10:17 +00:00