Commit Graph

104 Commits

Author SHA1 Message Date
Benjamin Otte
2a78adc5e3 Only add object to list new objects when it has a custom constructor
This works around the need to take a custom mutex twice and add the
object to a GSList of objects that are currently in construction for the
common case. Only when the constructor is overwritten do we use the
previous behavior and allow things like singleton objects.

The only slightly incompatible change is that previously, it was ok to
call g_object_set() on construct-only properties while the object was
initialized. This will now fail. If that behavior is needed, setting a
custom constructor that just chains up will reenable this functionality.

https://bugzilla.gnome.org/show_bug.cgi?id=557151
2009-11-30 20:52:33 +01:00
Cody Russell
855deaa578 g_object_unref racy condition can lead to crash
Store whether the object has a toggleref before decrementing the
refcount to prevent race condition when two threads simultaneously
try to unref an object with a refcount of 2.
Patch by Antoine Tremblay.

https://bugzilla.gnome.org/show_bug.cgi?id=551706
2009-10-06 12:27:12 -04:00
Alexander Larsson
1937765f9f Add fast path for construction with no params
This avoids a bunch of code and makes construction of simple objects
faster.

Object construction performance improvement:
         Non-Threaded   Threaded
Simple:           14%         5%
Complex:        -1.1%      -2.2%

Other tests stable.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Alexander Larsson
ffc625ec9b Don't freeze/thaw notification during construction if no properties
If the class has no properties there could be no notification anyway.
This is an important optimization for construction of simple objects.

Object construction performance improvement:
         Non-Threaded   Threaded
Simple:           84%        91%
Complex:        -1.4%      -0.6%

Other tests stable.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Alexander Larsson
302d13a757 Add a check that no properties are added after a class is derived
We can't support that, because that would cause the CLASS_HAS_PROPS_FLAG
class flag to not be correct.
2009-10-02 21:02:48 +02:00
Alexander Larsson
39a1fe5782 Add GObjectClass flag CLASS_HAS_PROPS_FLAG
This is set if a class or any of its parents have installed any
properties.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Matthias Clasen
f548330275 Fix "it's" vs "its" confusion throughout the source. Patch by Will
* Fix "it's" vs "its" confusion throughout the source. Patch
        by Will Thompson.


svn path=/trunk/; revision=7897
2009-02-23 04:30:06 +00:00
Matthias Clasen
c8e37b63e7 Fix strict aliasing warnings and viiolations to make GLib and
GLib users buildable with gcc 4.4. Patch by Jakub Jelinek.

        * glib/gatomic.[hc]: Add G_GNUC_MAY_ALIAS to pointer arguments,
        fix macro versions to only operate on objects of the same size.

        * glib/gdataset.c:
        * glib/gthread.[hc]:
        * glib/gdatasetprivate.h: Remove unnecessary casts in
        g_atomic_pointer_get calls.


svn path=/trunk/; revision=7875
2009-02-17 16:14:39 +00:00
Behdad Esfahbod
bf201e0fb7 Bug 565136 – Gobject's "notify" signal parameters are wrong in gtk-doc
2009-01-02  Behdad Esfahbod  <behdad@gnome.org>

        Bug 565136 – Gobject's "notify" signal parameters are wrong in gtk-doc
        Patch from  Andrzej Zaborowski

        * gobject.c (g_object_do_class_init): Fix param order in docs.


svn path=/trunk/; revision=7759
2009-01-02 06:09:26 +00:00
Matthias Clasen
8b14e3744c Expand the docs of g_object_class_install_property. Proposed by Maciej
* gobject.c: Expand the docs of g_object_class_install_property.
Proposed by Maciej Piechotka

svn path=/trunk/; revision=7642
2008-11-04 04:17:40 +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
Johan Dahlin
306db46123 Bug 548800 – Missing a g_object_get_type function
2008-08-21  Johan Dahlin  <johan@gnome.org>

    Bug 548800 – Missing a g_object_get_type function

    * gobject.c (g_object_get_type):
    * gobject.h:
    * gobject.symbols:
    Add g_object_get_type


svn path=/trunk/; revision=7377
2008-08-21 09:18:25 +00:00
Michael Natterer
6f1f1342e4 remove unused #define PREALLOC_CPARAMS.
2008-07-04  Michael Natterer  <mitch@imendio.com>

	* gobject.c: remove unused #define PREALLOC_CPARAMS.


svn path=/trunk/; revision=7159
2008-07-04 13:08:39 +00:00
Matthias Clasen
d6d221911d Fix up section comments
svn path=/trunk/; revision=7137
2008-07-02 03:43:13 +00:00
Björn Lindqvist
eba8246ce5 Bug 539626 – Update docstrings for g_object_freeze_notify and
2008-06-29  Björn Lindqvist  <bjourne@gmail.com>

	Bug 539626 – Update docstrings for g_object_freeze_notify and
	g_object_thaw_notify

	* gobject/gobject.c: Explain how the freeze count works.

svn path=/trunk/; revision=7102
2008-06-29 12:09:31 +00:00
Michael Natterer
6347be5fb6 remove trailing whitespace from newly added gtk-doc comments and
2008-06-22  Michael Natterer  <mitch@imendio.com>

	* *.c: remove trailing whitespace from newly added gtk-doc
	comments and reformatted some where they contained overly long or
	ill-formatted lines.


svn path=/trunk/; revision=7090
2008-06-22 14:53:09 +00:00
Michael Natterer
5602b7e275 moved includes back to the top of the files (before gtk-doc SECTION
2008-06-22  Michael Natterer  <mitch@imendio.com>

	* *.c: moved includes back to the top of the files (before gtk-doc
	SECTION comments). Add "config.h" in all files and move system
	included before glib includes. Remove trailing whitespace from
	SECTION comments and did some reformatting where lines were overly
	long, no documentation content was changed.


svn path=/trunk/; revision=7089
2008-06-22 14:29:25 +00:00
Stefan Kost
356fe46531 Migrating docs.
* docs/reference/gobject/tmpl/signals.sgml:
	* gobject/gclosure.c:
	* gobject/gobject.c:
	* gobject/gsignal.c:
	* gobject/gsignal.h:
	  Migrating docs.


svn path=/trunk/; revision=7083
2008-06-22 09:29:52 +00:00
Stefan Kost
fca3fb5818 Migrating docs.
* docs/reference/gobject/tmpl/param_value_types.sgml:
	* gobject/gboxed.c:
	* gobject/gboxed.h:
	* gobject/genums.c:
	* gobject/genums.h:
	* gobject/gobject.c:
	* gobject/gobject.h:
	* gobject/gparam.c:
	* gobject/gparam.h:
	* gobject/gparamspecs.c:
	* gobject/gparamspecs.h:
	* gobject/gvaluetypes.c:
	* gobject/gvaluetypes.h:
	  Migrating docs.


svn path=/trunk/; revision=7081
2008-06-21 22:16:14 +00:00
Stefan Kost
fedbbf5d74 Migrating docs.
* docs/reference/gobject/tmpl/objects.sgml:
	* gobject/gobject.c:
	* gobject/gobject.h:
	* gobject/gparam.h:
	  Migrating docs.


svn path=/trunk/; revision=7080
2008-06-21 20:07:57 +00:00
Stefan Kost
83dd545044 Migrating docs.
* docs/reference/gobject/tmpl/gclosure.sgml:
	* gobject/gboxed.h:
	* gobject/gclosure.c:
	* gobject/gclosure.h:
	* gobject/gobject.c:
	* gobject/gsourceclosure.c:
	* gobject/gsourceclosure.h:
	  Migrating docs.


svn path=/trunk/; revision=7069
2008-06-21 12:18:12 +00:00
Ryan Lortie
dac885cba5 invoke GObjectClass.constructed() only for newly constructed objects, and
Tue Apr  3 12:34:14 2007  Tim Janik  <timj@gtk.org>

        * gobject.[hc]: invoke GObjectClass.constructed() only for newly
        constructed objects, and invoke it while the notify queue is
        still being frozen, after all CONSTRUCT* properties have been
        set and before random other properties are being set.

        * applied modified patch from Ryan Lortie to implement
        GObjectClass.constructed() to fix #425324.

2007-04-02  Ryan Lortie  <desrt@desrt.ca>

        * gobject/gobject.h: Add 'constructed' vcall to GObjectClass.
        * gobject/gobject.c (g_object_newv): call ->constructed() as last
        step of object construction.



svn path=/trunk/; revision=5441
2007-04-03 10:44:30 +00:00
Matthias Clasen
20b39ffafa Fix some issues with PLT entries. 2006-09-30 13:59:01 +00:00
Tim Janik
08e3a830fb fixed to print usage and version info on STDOUT (#322502).
Tue Aug 29 13:27:33 2006  Tim Janik  <timj@gtk.org>

        * glib-mkenums.in: fixed to print usage and version info on STDOUT
        (#322502).

        * gobject.c (g_initially_unowned_init): restore ; after G_DEFINE_TYPE.
2006-08-29 11:29:24 +00:00
Matthias Clasen
ed9c3c2696 Fix some typos. (#351741, Kjartan Maraas)
2006-08-26  Matthias Clasen  <mclasen@redhat.com>

	* glib/gutils.h:
	* glib/gscanner.c: Fix some typos.  (#351741, Kjartan Maraas)
2006-08-26 04:03:37 +00:00
Sven Neumann
89f9ebaef3 changed return value of g_value_dup_object(), fixes #343292.
Wed Aug 23 10:35:32 2006  Tim Janik  <timj@gtk.org>

        * gobject.[hc]: changed return value of g_value_dup_object(), fixes #343292.

2006-08-23  Sven Neumann  <sven@gimp.org>

        * gobject/glib-genmarshal.[c1]: added new command-line option
        "--internal" that can be used to let glib-genmarshal generate
        internal functions using the G_GNUC_INTERNAL attribute (bug #346647).
2006-08-23 08:46:21 +00:00
Tim Janik
13fe93378e conditionally thaw the notify queue after construction, so we don't
Wed Aug 16 13:55:08 2006  Tim Janik  <timj@imendio.com>

        * gobject.c: conditionally thaw the notify queue after construction,
        so we don't trigger warnings when trying to thaw an unfrozen singleton.
2006-08-16 12:09:51 +00:00
Tim Janik
e9b421f212 added case3 to hand out the original floating flag handler. required by
Tue Mar  7 17:09:07 2006  Tim Janik  <timj@gtk.org>

        * gobject.c (g_object_compat_control): added case3 to hand out the
        original floating flag handler. required by gtk+ >= 2.10.
2006-03-07 16:15:20 +00:00
Tim Janik
648da9d63f renamed GUnowned to GInitiallyUnowned.
Thu Dec 22 18:53:14 2005  Tim Janik  <timj@gtk.org>

        * gobject.[hc]: renamed GUnowned to GInitiallyUnowned.
2005-12-22 17:58:21 +00:00
Tim Janik
6f01d0c34f implemented G_TYPE_GTPYE. applied patch from matthias which implements
Thu Dec 22 14:59:24 2005  Tim Janik  <timj@imendio.com>

        * gvaluetypes.[hc]: implemented G_TYPE_GTPYE. applied patch
        from matthias which implements GType accessors for GValue.

        * gparamspecs.[hc]: applied patch from matthias which
        implements G_TYPE_PARAM_GTYPE.

        * gobject.[hc]:
        GUnowned: introduced a new object type that has an initially
        floating reference.
        g_object_compat_control(): allow setting of a floating flag handler.
2005-12-22 15:07:03 +00:00
Tim Janik
6e5f465924 added floating reference count. g_object_is_floating():
Wed Nov 23 18:01:46 2005  Tim Janik  <timj@imendio.com>

        * gobject.[hc]: added floating reference count.
        g_object_is_floating():
        g_object_ref_sink(): new functions to deal with floating references.
        g_object_force_floating(): new funciton for object implementations
        to set the floating flag.

        * gobject.c (g_object_init): make objects initially floating.

Wed Nov 23 17:58:13 2005  Tim Janik  <timj@gtk.org>

        * gparam.[hc]: added g_param_spec_ref_sink().
2005-11-23 17:54:41 +00:00
Matthias Clasen
f7a681d65d Intern the signal name.
2005-08-31  Matthias Clasen  <mclasen@redhat.com>

	* gobject.c (g_object_do_class_init): Intern the signal name.
2005-08-31 19:42:51 +00:00
Matthias Clasen
07c4d80d55 Intern type names before registering the type to avoid unnecessary copies.
2005-08-31  Matthias Clasen  <mclasen@redhat.com>

	* gvaluetypes.c (g_value_types_init):
	* gtypeplugin.c (g_type_plugin_get_type):
	* gtypemodule.c (g_type_module_get_type):
	* gparam.c (g_param_type_init):
	* gobject.c (g_object_type_init):
	* genums.c (g_enum_types_init):
	* gboxed.c (g_boxed_type_init): Intern type names
	before registering the type to avoid unnecessary
	copies.
2005-08-31 14:38:18 +00:00
Tim Janik
834ddd1920 turned all modifications to the first 32 integer bits in a closure into
Mon Aug  1 23:00:42 2005  Tim Janik  <timj@imendio.com>

        * gclosure.c: turned all modifications to the first 32 integer bits in a
        closure into atomic accesses. wrapped write accesses into special macros
        to keep the atomic modification logic in a single place. comment cleanups.

        * gclosure.h: made all atomicly accessed closure fields volatile.

        * gobject.h: made ref_count field volatile.
2005-08-01 21:17:50 +00:00
Tim Janik
4746cf2ce0 use g_datalist_set_flags() and g_datalist_unset_flags() to allow proper
Sun Jul 31 02:04:23 2005  Tim Janik  <timj@gtk.org>

        * gobject.c: use g_datalist_set_flags() and g_datalist_unset_flags() to
        allow proper locking around &qdata modifications.
2005-07-31 00:05:22 +00:00
Tim Janik
f0cfc267ba reverted notify_mutex introduction, since this prevents parallelized
Sat Jul 30 21:10:26 2005  Tim Janik  <timj@gtk.org>

        * gobject.c: reverted notify_mutex introduction, since this prevents
        parallelized setting of object properties on different objects, and
        serves no apparent purpose (to me at least).
        g_object_real_dispose(): removed non-atomic reference count
        modifications.
        g_object_unref(): make sure the closures array is destroyed when
        destroying signal handlers.

        * gparam.c: cosmetic changes.

        * gsignal.c: comment fixup. allow 16bit blocking count.

        * gsignal.c: reverted GClosure related changes.

        * gclosure.c: reverted premature commit of atomic reference
        counting attempt.
2005-07-30 19:46:11 +00:00
Matthias Clasen
39ea11ce6b Make refcounting threadsafe by using atomic operations. (#166020, Wim
2005-07-15  Matthias Clasen  <mclasen@redhat.com>

	Make refcounting threadsafe by using atomic
	operations.  (#166020, Wim Taymans)

	* gobject.c: Use a recursive lock to protect the
	notify queue.
	(g_object_unref): Get rid of g_object_last_unref and
	do the last unref handling in g_object_unref.
	(g_object_ref, g_object_unref): Use atomic operations.

	* gsignal.c (struct _HandlerMatch): Use a full integer
	for the ref_count field.
	(handler_ref, handler_unref_R): Use atomic operations.

	* gparam.c (g_param_spec_ref, g_param_spec_unref):
	Use atomic operations instead of a lock to make the
	refcounting threadsafe.

	* gclosure.c (g_closure_ref, g_closure_unref): Use atomic
	operations. This is more complicated here, since the
	refcount is stored in a bitfield, so we also have
	to access all other bitfield members atomically.

	* gsignal.c (handlers_find): Read the meta_marshal flag
	of the closure atomically.

	* tests/Makefile.am (SUBDIRS): Add tests/refcount

	* configure.in: Add tests/refcount

	* tests/refcount/properties.c: Test property changes
	from multiple threads.

	* tests/refcount/signals.c: Test signal emission from
	multiple threads.

	* tests/refcount/objects.c: Test refcounting from
	multiple threads.

	* tests/refcount/objects2.c:
	* tests/refcount/properties2.c: Tests to measure the
	overhead of threadsafe refcounting.

	* glib/giochannel.c (g_io_channel_ref, g_io_channel_unref):
	Use atomic operations to make refcounting
	threadsafe.  (#166020, Wim Taymans)
2005-07-15 16:51:10 +00:00
Owen Taylor
2ae1a46b4c Add g_object_add/remove_toggle_ref() functions to get notification when a
2005-05-05  Owen Taylor  <otaylor@redhat.com>

        * gobject.[ch] gobject.symbols: Add
        g_object_add/remove_toggle_ref() functions to get notification
        when a reference count is the last remaining reference; this
        enables better memory management for language bindings.
        (http://mail.gnome.org/archives/gtk-devel-list/2005-April/msg00095.html)

2005-05-05  Owen Taylor  <otaylor@redhat.com>

        * glib/gdataset.[ch] glib/gdatasetprivate.h: Add
        g_datalist_set/unset_flags(), g_datalist_get_flags() functions
        to squeeze some bits into a GDataSet... this is needed for
        efficient implementation of toggle references in GObject.

        * tests/gobject/references.c tests/gobject/Makefile.am:
        Add a test case for weak and toggle references.

        * glib/gfileutils.[ch]: Rename g_file_replace() back
        to g_file_set_contents().

        * glib/glib.symbols: Update.

2005-05-05  Owen Taylor  <otaylor@redhat.com>

        * glib/Makefile.am glib/glib-sections.txt gobject/gobject-sections.txt:
        Update

        * gobject/tmpl/objects.sgml: Document toggle-references.
2005-05-05 14:57:29 +00:00
Matthias Clasen
3448a27829 Make work again.
2005-03-14  Matthias Clasen  <mclasen@redhat.com>

	* abicheck.sh: Make work again.

	* gsourceclosure.c: Fix a typo.

	Make PLT-reduction work with gcc4, and don't include
	everything in gobjectalias.h:

	* gobject.symbols: Group symbols by header and source
	file.
	* makegobjectalias.pl: Protect definitions by the same
	preprocessor symbols used to guard the headers. Move
	the alias declarations to a separate file which is
	produced when calling makegalias.pl -def
	* Makefile.am (gobjectaliasdef.c): Add a rule to
	build this file.
	* *.c: Include gobjectalias.h after the other i
        GLib headers, include gobjectaliasdef.c at the bottom.
2005-03-14 06:47:51 +00:00
Matthias Clasen
465c7d1ead Implement the same PLT reduction technique used in GTK+:
2004-09-16  Matthias Clasen  <mclasen@redhat.com>

	Implement the same PLT reduction technique used in GTK+:

	* Makefile.am: Generate gobjectalias.h from gobject.symbols.
	(BUILT_SOURCES): Add gobjectalias.h.

	* makegobjectalias.pl: Script to generate gobjectalias.h.

	* *.c: Include gobjectalias.h
2004-09-16 18:52:40 +00:00
Tim Janik
aa63f7e373 fix g_object_set() whithin _init() implementations not working for
Sat Nov 29 14:57:20 2003  Tim Janik  <timj@gtk.org>

        * gobject.c: fix g_object_set() whithin _init() implementations
        not working for construct-only properties.
        (g_object_init): make the object enter a construct_objects list.
        (g_object_newv): remove object from construct_objects after creation.
        (g_object_set_valist):
        (g_object_set_property): allow construct-only properties for
        objects which are in construct_objects.
2003-11-29 14:00:06 +00:00
Tim Janik
0642df0ab3 variant of class_peek() which works for static types only.
Thu Nov 27 17:53:52 2003  Tim Janik  <timj@gtk.org>

        * gtype.[hc]:
        (g_type_class_peek_static): variant of class_peek() which works for
        static types only.

        * gobject.c:
        (g_object_do_class_init): make ::notify a run-action signal.
        (g_object_newv): use g_type_class_peek_static() by default to
        speed up common code path (trades two write-locks for one read-lock).
        (g_object_disconnect):
        (g_object_connect): allow signal specification words to be
        seperated by '-'.
        (g_object_set_valist):
        (g_object_new_valist): don't leak values.
        (g_object_get_property): check property for readability.
        (g_object_set_property): check property for writability and to
        not be construct-only.
        (g_object_set_valist): check property to not be construct-only.
2003-11-27 17:08:06 +00:00
Owen Taylor
6f5794fad0 Add a new GParamSpecOverride type that is a pointer to a different
Tue Oct 14 17:40:19 2003  Owen Taylor  <otaylor@redhat.com>

        * gparamspecs.[ch]: Add a new GParamSpecOverride type
        that is a pointer to a different paramspec in a parent
        class or interface.

        * gparam.[ch]: Add g_paramspec_get_redirect_target()
        which follows GParamSpecOverride to the real property.
        Make g_param_spec_pool_list() hand redirections,
        properties on interfaces.

        * gobject.[ch] gobjectnotifyqueue.c: Add
        g_object_interface_install_property,
        g_object_interface_find_property,
        g_object_interface_list_properties(). Redirect virtually all
        publically exposed GParamSpec's to the redirect target if
        any. (->constructor is the exception.)
        (#105894)
2003-10-21 19:12:27 +00:00
Matthias Clasen
c3acb9da0c Make the g_value_set_x_take_ownership() functions "official" part of the
2003-09-12  Matthias Clasen  <maclas@gmx.de>

	Make the g_value_set_x_take_ownership() functions "official"
	part of the API (#100948):

	* gvaluetypes.[hc]: Add g_value_take_string() (synonym to the
	now deprecated g_value_set_string_take_ownership()).

	* gparam.[hc]: Add g_value_take_param() (synonym to the
	now deprecated g_value_set_param_take_ownership()).

	* gobject.[hc]: Add g_value_take_object() (synonym to the
	now deprecated g_value_set_object_take_ownership()).

	* gboxed.[hc]: Add g_value_take_boxed() (synonym to the
	now deprecated g_value_set_boxed_take_ownership()).

	* gobject/gobject-sections.txt: Add new g_value_take_x() functions.

	* gobject/tmpl/param_value_types.sgml: Document new g_value_take_x()
	functions.  (#100948)
2003-09-12 20:11:38 +00:00
Manish Singh
056041aab9 removed stray change from previous commit.
Wed Aug 27 19:53:26 2003  Manish Singh  <yosh@gimp.org>

        * gobject.c: removed stray change from previous commit.
2003-08-28 02:55:58 +00:00
Matthias Clasen
29606d90b0 Improve the wording of the warning for invalid
values.  (#117246, Mariano Suarez-Alvarez)
2003-08-08 19:47:35 +00:00
Owen Taylor
68e49c7811 Order refs/unrefs so setting the same object back is safe. (#112861,
Fri May 30 14:42:24 2003  Owen Taylor  <otaylor@redhat.com>

        * gobject.c (g_value_set_object): Order refs/unrefs
        so setting the same object back is safe. (#112861,
        Morten Welinder)
2003-05-30 18:44:57 +00:00
Matthias Clasen
fa21b512d5 Remove all docs from gobject at Tims request. Documentation is only for
2003-02-07  Matthias Clasen  <maclas@gmx.de>

	* gtypemodule.c:
	* gtype.c:
	* gsourceclosure.c:
	* gparamspecs.c:
	* gparam.c:
	* gobject.c:
	* gsignal.c: Remove all docs from gobject at Tims
	request. Documentation is only for weenies anyway...
2003-02-07 22:04:24 +00:00
Matthias Clasen
634b48f254 Add docs. 2002-12-18 23:46:18 +00:00
Matthias Clasen
8b8616bb9c Move some docs inline.
* gobject/tmpl/param_value_types.sgml: Move some docs inline.

	* gsignal.c (g_signal_new): Typo fix.

	* gparamspecs.c:
	* gparam.c (g_param_spec_internal):
	* gobject.c (g_object_class_install_property): Add docs.
2002-12-15 02:38:49 +00:00