Commit Graph

62 Commits

Author SHA1 Message Date
Matthias Clasen
e79af74d1b gobject: Always ref-sink variants in g_object_set
When collecting varargs, ignore the NOCOPY_CONTENTS
flag for variants. That is what our docs advice for
refcounted types, and it fixes a regression that
was inadvertendly introduced when we stopped doing
some extra GValue copies.

Includes a test case by Philip Withnall.

Fixes: #2774
2022-10-24 10:47:35 +01:00
Philip Withnall
26409f19cd Add SPDX license headers for LGPL-2.1-or-later to various files
These have all been added manually, as I’ve finished all the files which
I can automatically detect.

All the license headers in this commit are for LGPL-2.1-or-later, and
all have been double-checked against the license paragraph in the file
header.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-06-01 12:44:23 +01:00
DarkTrick
1fc905efe4 g_value_set_string description: clarified (unified), that v_string is a copy. 2021-06-23 05:50:59 +00:00
Edward Hervey
e21ab81ce0 gvalue: Do copy non-interned strings
The G_VALUE_NOCOPY_CONTENTS for strings can only be used when collecting them
and not when copying them.

Instead only avoid copies for strings that are interned.

Fixes #2141
2020-06-23 10:30:55 +00:00
Edward Hervey
898baa07b1 gobject: Handle runtime checks as such
The various `g_strdup_printf()` returns values in the implementations of GValue
lcopy_func are runtime checks which could be disabled if one wants and therefore
should be handled as such with g_return_val_if_fail()
2020-05-20 17:37:46 +02:00
Edward Hervey
1a95ce84ed GValue: Add interned string support
This adds support to be able to explicitely stored interned strings into
G_TYPE_STRING GValue.

This is useful for cases where the user:
* *knows* the string to be stored in the GValue is canonical
* Wants to know whther the string stored is canonical

This allows:
* zero-cost GValue copy (the content is guaranteed to be unique and exist
  throughout the process life)
* zero-cost string equality checks (if both string GValue are interned, you just
  need to check the pointers for equality or not, instead of doing a strcmp).

Fixes #2109
2020-05-19 17:52:55 +02:00
Edward Hervey
e3efbd30a2 gvalue: Static strings should not be copied
When doing copies of GValue backed by static strings, the contents should not be copied
2020-05-19 17:52:55 +02:00
Philip Withnall
3d3ca9f1fe gobject: Fix various compiler warnings when compiling with G_DISABLE_ASSERT
Mostly unused variables which are only used in a g_assert() call
otherwise.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1708
2019-03-08 19:46:21 +00:00
Christoph Reiter
f73b9e29e1 g_value_get_variant: return value is transfer-none not transfer-full
It defaulted to transfer-full.
2018-11-25 13:05:54 +01:00
Philip Withnall
aca410c586 gobject: Add missing annotations to GValue variant methods
They were missing some (nullable) and (transfer) annotations.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=741167
2017-11-28 14:29:36 +00:00
Sébastien Wilmet
6b948d9613 gobject/: LGPLv2+ -> LGPLv2.1+
All gobject/*.{c,h} files have been processed.

gmarshal.c and gmarshal.h don't have a license header.

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-24 11:58:19 +02:00
Christian Hergert
18a33f72db introspection: use (nullable) or (optional) instead of (allow-none)
If we have an input parameter (or return value) we need to use (nullable).
However, if it is an (inout) or (out) parameter, (optional) is sufficient.

It looks like (nullable) could be used for everything according to the
Annotation documentation, but (optional) is more specific.
2016-11-22 14:14:37 -08:00
Rico Tzschichholz
e3189527dc gio/gobject: Various introspection fixes 2016-02-03 18:13:49 +01:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01: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
Benjamin Otte
9d52243790 values: Use v_pointer for g_value_set_gtype()
... and g_value_get_gtype(). G_TYPE_GTYPE is a pointer type, so it's
values should use the v_pointer member. This is especially true, because
the value collectors from varargs in gvaluecollector.h use that, too.

This should only cause issues when sizeof(glong) != sizeof(gpointer),
and I'm not aware of any such platform. Maybe win64?
2012-01-14 01:15:16 +01:00
Nicola Fontana
f24d8247b3 Do not use static GTypeInfo and GInterfaceInfo
Either g_type_register_static_simple (used by G_DEFINE_TYPE_EXTENDED)
and G_IMPLEMENT_INTERFACE use automatic variables for GTypeInfo and
GInterfaceInfo structs, while tutorials and source code often use
static variables. This commit consistently adopts the former method.

https://bugzilla.gnome.org/show_bug.cgi?id=600161
2011-11-29 22:03:25 -05:00
Javier Jardón
108480b7ba gobject: Use G_VALUE_INIT 2011-10-18 17:12:33 +01:00
Colin Walters
f42fe6cdc0 gvalue: Add explicitly signed g_value_get_schar() and g_value_set_schar()
The documentation for G_TYPE_CHAR says:

"The type designated by G_TYPE_CHAR is unconditionally an 8-bit signed
 integer."

However the return value for g_value_get_char() was just "char" which
in C has an unspecified signedness; on e.g. x86 it's signed (which
matches the GType), but on e.g. PowerPC or ARM, it's not.

We can't break the old API, so we need to suck it up and add new API.
Port most internal users, but keep some tests of the old API too.

https://bugzilla.gnome.org/show_bug.cgi?id=659870
2011-09-22 20:05:38 -04:00
Pavel Holejsovsky
de6566b07d Add missing (allow-none) annotations to g_value_set_string functions 2011-08-19 11:44:41 +02:00
Pavel Holejsovsky
d4c5e3b156 Add (allow-none) annotation for GValue setters.
Assorted g_value_set_xxx() and g_value_take_xxx() functions actually
allow NULL in source parameter.
2011-08-17 12:55:12 +02:00
Ryan Lortie
58c247e51b GVariant: add g_variant_take_ref()
This function implements the following logic:

  if (g_variant_is_floating (value))
    g_variant_ref_sink (value);

which is used for consuming the return value of callbacks that may or
may not return floating references.

This patch also replaces a few instances of the above code with the new
function (GSettings, GDBus) and lifts a long-standing restriction on the
use of floating values as the return value for signal handlers by
improving g_value_take_variant().

https://bugzilla.gnome.org/show_bug.cgi?id=627974
2011-07-12 19:44:21 +02:00
Ryan Lortie
ce9681b87e Drop a few more G_CONST_RETURN 2011-06-13 09:27:28 -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
Pavel Holejsovsky
ea577d60d4 Add GI annotations to GValue and GValueArray. 2010-12-19 10:39:36 +01:00
Will Thompson
ba17efc396 g_strdup_value_contents(): dump GStrv more usefully
Previously, dumping a GValue holding a GStrv just yielded "((GStrv *)
0xDEADBEEF)". I think it'd be more useful to dump a Python list-style
representation of the GStrv's contents, if it's not NULL.

Fixes: <https://bugzilla.gnome.org/show_bug.cgi?id=629192>
2010-09-13 19:19:46 +01:00
Christian Persch
71e73ffdfb Use G_DEFINE_[BOXED|POINTER]_TYPE instead of handwritten code
Now that we have convenience macros to implement boxed and pointer
types, use them.
2010-08-18 00:12:28 +02:00
Ryan Lortie
0fc50fa5f7 gobject/: fully remove gobjectalias hacks 2010-07-07 19:40:48 -04:00
Christian Persch
2d4e48b73c Tiny docs fix 2010-06-19 20:04:20 +02:00
Christian Persch
db68f8203a Add g_value_take_variant
Turns out we do need g_value_take_variant(), so we can correctly
implement VARIANT:* marshalers.

Bug #621947.
2010-06-19 19:07:36 +02:00
Matthias Clasen
19a752a5f4 fix a typo 2010-06-17 15:53:08 -04:00
Christian Persch
4708b8ecc3 Add fundamental type and pspec for GVariant
Make G_TYPE_VARIANT a fundamental type instead of boxed, and add
g_variant_{set,get,dup}_variant.

Add GParamSpecVariant.

Bug #610863.
2010-06-17 21:00:54 +02:00
Matthias Clasen
63802ac67d Clarify some docs
svn path=/trunk/; revision=7280
2008-08-01 18:36:01 +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
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
0b9bf79ec2 Migrating docs.
* docs/reference/gobject/tmpl/generic_values.sgml:
	* gobject/gboxed.h:
	* gobject/gtype.h:
	* gobject/gvalue.c:
	* gobject/gvalue.h:
	* gobject/gvaluetypes.c:
	  Migrating docs.


svn path=/trunk/; revision=7071
2008-06-21 12:45:49 +00:00
Stefan Kost
86a0f779f6 Migrating docs.
* docs/reference/gobject/tmpl/gboxed.sgml:
	* gobject/gboxed.c:
	* gobject/gboxed.h:
	* gobject/gvaluetypes.c:
	  Migrating docs.


svn path=/trunk/; revision=7065
2008-06-21 10:19:58 +00:00
Matthias Clasen
20b39ffafa Fix some issues with PLT entries. 2006-09-30 13:59:01 +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
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
Matthias Clasen
b5c20b801c dup the new value before freeing the old, just in case. (#172142, Morten
2005-05-20  Matthias Clasen  <mclasen@redhat.com>

	* gvaluetypes.c (g_value_set_string): dup the new value
	before freeing the old, just in case.  (#172142, Morten
	Welinder)
2005-05-20 20:51:38 +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
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
Owen Taylor
49d9628efc Add a function g_pointer_type_register_static() to register a type derived
Sun Nov  4 14:01:23 2001  Owen Taylor  <otaylor@redhat.com>

        * gvaluetypes.[ch]: Add a function g_pointer_type_register_static()
        to register a type derived from G_TYPE_POINTER.
2001-11-04 19:02:10 +00:00
Tim Janik
a7cba8a50a cosmetic fixups.
Fri Oct 12 18:40:18 2001  Tim Janik  <timj@gtk.org>

        * cosmetic fixups.
2001-10-12 16:42:48 +00:00
Joshua N Pritikin
d23c9a8ba8 Fill in missing support for gint64 & guint64 (#59254).
* glib-genmarshal.c gparamspecs.[ch] gtype.[ch] gvalue.h
gvaluecollector.h gvaluetypes.[ch]: Fill in missing support for
gint64 & guint64 (#59254).

* Unconditionalize same (compile with or without G_HAVE_INT64).
2001-10-11 02:43:04 +00:00