Commit Graph

1587 Commits

Author SHA1 Message Date
Philip Withnall
5b7c109e1c gclosure: Clarify when destroy notifiers are called in documentation
They’re called in finalize, not invalidate.

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

https://gitlab.gnome.org/GNOME/glib/issues/277
2018-08-16 10:58:43 +01:00
Christoph Reiter
0319dac01d g_binding_unbind: make it more introspection friendly; allow calling it multiple times. Fixes #1373
g_object_bind_property() (transfer none) returns a GBinding with an existing internal
reference which is active as long as the "binding" is. This allows to optionally use
the binding without any memory management, as it will remove itself when it is no longer
needed.

There are currently three ways to remove the "binding" and as a result the reference:

1) Either the source or target dies and we get notified by a weakref callback
2) The user unrefs the binding until it is destroyed (which is semi-legal,
   but worked and is used in the test suite)
3) The user calls g_binding_unbind()

In case (3) the problem was that it always calls unref even if the "binding" is already
gone, leading to crashes when called from bindings multiple times.
In #1373 and !197 it was noticed that a function always unrefs which would be a
"transfer full" annotation, but the problem here is that it should only remove the
ref when removing the "binding" and the annotation should stay "transfer none".

As a side effect of this fix it is now also possible to call g_binding_unbind() multiple
times where every call after the first is a no-op.

This also adds explicit tests for case (1) and (3) - only case (3) is affected by this change.
2018-08-16 11:27:34 +02:00
Will Thompson
de62a95d5e
glib-mkenums: improve and correct argument documentation
ftail is not per-input-file, it is the footer for the entire output
file.

You cannot have fewer informations.
2018-08-10 17:18:36 +01:00
Will Thompson
7928fee2a8
glib-mkenums: don't support @filename@/@basename@ in fhead/ftail
As discussed in
https://gitlab.gnome.org/GNOME/glib/merge_requests/135#note_253986 it
doesn't really make sense to support these outside the templates for any
particular header file. Leave them unsubstituted, with a warning.
2018-08-10 17:05:59 +01:00
Will Thompson
cbd335c8c9
tests: mkenums: placate flake8 2018-08-10 17:05:59 +01:00
Will Thompson
12a2a984f2
tests: refactor running glib-mkenums
Part of runMkenumsWithHeader() was duplicated in test_reproducible(),
and would otherwise need to be duplicated again in upcoming tests.  Many
places duplicated decoding stdout/stderr and checking the exit code.

Introduce a named tuple for the returned fields; and factor out writing
a template file to pass with --template.
2018-08-10 17:05:59 +01:00
Philip Withnall
2500dfe3b3 docs: Fix a documentation link
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 21:15:57 +01:00
Sebastian Dröge
c66c277e24 Fix annotation of g_binding_unbind() to transfer-full
It takes ownership of the binding reference passed in as described in
the documentation already.
2018-07-25 15:52:04 +03:00
Nirbheek Chauhan
4e1488eebb Merge branch 'meson-python-module' into 'master'
meson: use the new 'python' module instead of the 'python3' one

Closes #1455

See merge request GNOME/glib!187
2018-07-23 11:17:47 +00:00
Christoph Reiter
631c3534b7 meson: use the new 'python' module instead of the 'python3' one. Closes #1455
The new python module, added with 0.46, works with Python 2 and 3 and
allows to pass a path for the interpreter to use, if the need arises.

Previously the meson build set PYTHON, used in the shebang line of
the scripts installed by glib, to the full path of the interpreter.
The new meson module doesn't expose that atm, but we should set it to
a executable name anyway, and not a full path.
2018-07-19 12:32:29 +02:00
Nirbheek Chauhan
057f393bbb meson: Provide our Python tools for builds
Several of our tools are installed and are used by other projects to
generate code. However, there is no 'install' when projects use glib
as a subproject.

We need some way for glib to 'provide' these tools so that when some
project uses glib as a subproject, find_program('glib-mkenums') will
transparently return the glib-mkenums we just built.

Starting from Meson 0.46, this can be done with the
`meson.override_find_program()` function.

As a bonus, the Meson GNOME module will also use these
'overriden'/'provided' programs instead of looking for them in PATH.
2018-07-19 15:53:37 +05:30
Philip Withnall
7f55c768ce Merge branch '1444-install-tests' into 'master'
Install unit tests

Closes #1444

See merge request GNOME/glib!183
2018-07-17 09:51:12 +00:00
Philip Withnall
16c6a73586 Merge branch 'add-g-has-typeof-1440' into 'master'
gmacros: Add new private g_has_typeof to abstract __typeof__ checks

Closes #1440

See merge request GNOME/glib!172
2018-07-17 09:27:12 +00:00
Philip Withnall
4dc6a01241 Merge branch 'type-safe-g-clear-pointer-1425' into 'master'
Type safe g clear pointer 1425

Closes #1425

See merge request GNOME/glib!177
2018-07-17 09:23:29 +00:00
Xavier Claessens
f456e311cd Meson: Use environment() for test_env 2018-07-16 15:04:03 -04:00
Iain Lane
4c621fb7ee gmacros: Add new private g_has_typeof to abstract __typeof__ checks
We have this same check in a few places now, and we might as well
abstract it out.

Fixes #1440.
2018-07-16 15:59:44 +01:00
Thomas Hindoe Paaboel Andersen
a8b416f9fe python: avoid equality check for None
PEP8 says that:
"Comparisons to singletons like None should always be done with is or
is not, never the equality operators."

glib uses a mix of "== None" and "is None". This patch changes all
cases to the latter.
2018-07-12 23:48:41 +02:00
Iain Lane
2aacef39b1 gobject: Make g_clear_object take a non-volatile GObject **
The implementation is silently discarding this anyway, and
g_object_unref() is using atomic operations. So this should be safe.

Having this here triggers -Wdiscarded-qualifiers when g_clear_pointer()
is fixed to use __typeof__().
2018-07-12 08:47:40 +01:00
Emmanuele Bassi
d3881bb1bf Revert "Merge branch 'type-safe-g-clear-pointer-1425' into 'master'"
This reverts merge request !165
2018-07-11 21:52:31 +00:00
Iain Lane
747c2f5720 gobject: Make g_clear_object take a non-volatile GObject **
The implementation is silently discarding this anyway, and
g_object_unref() is using atomic operations. So this should be safe.

Having this here triggers -Wdiscarded-qualifiers when g_clear_pointer()
is fixed to use __typeof__().
2018-07-11 10:52:53 +01:00
Philip Withnall
e818089b70 tests: Fix use-after-free in reference tests
Switch the check which tests whether the object has been finalised from
being a use-after-free, to using a weak pointer which is nullified on
finalisation.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-29 13:55:24 +01:00
Philip Withnall
ffb1c3cb74 tests: Various minor leak fixes in the GObject tests
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-29 12:13:32 +01:00
Philip Withnall
76083b6530 tests: Add glib-mkenums test for missing nicks
This adds a test to verify the change from issue #1360.

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

https://gitlab.gnome.org/GNOME/glib/issues/1360
2018-06-25 13:39:13 +01:00
Philip Withnall
e8d755eb8e tests: Add initial test framework for glib-mkenums
This allows running glib-mkenums with different C headers and checking
its output.

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

https://gitlab.gnome.org/GNOME/glib/issues/1360
2018-06-25 13:39:13 +01:00
Peter Kjellerstedt
c0e6fa4f19 glib-mkenums: Ignore other per value options than 'skip' and 'nick'
If some other per value option was present than 'skip' or 'nick' then
a KeyError would occur. Ignoring such options matches the behaviour of
the old, Perl-based glib-mkenums.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>

https://gitlab.gnome.org/GNOME/glib/issues/1360
2018-06-25 13:39:13 +01:00
Philip Withnall
877f20d0d8 gobject: Add prefixes to variables in G_VALUE_COLLECT*() macros
This makes them a bit more unique (and, crucially, in the g_* namespace)
to avoid shadowing collisions with calling code.

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

https://gitlab.gnome.org/GNOME/glib/issues/258
2018-06-20 16:00:48 +01:00
Emmanuele Bassi
7e5db31d36 Deprecate g_type_class_add_private()
It's been 4 years and 8 development cycles since we introduced
G_ADD_PRIVATE and offset-based private data access. It is now
time to finally deprecate the old mechanism.

Closes: #699
2018-06-14 11:33:53 +01:00
Emmanuele Bassi
16d1a3d28c Classify the tests
Meson has the ability to classify tests according to "suites", a list of
tags. This is especially useful when we want to run specific sets of
tests — e.g. only GLib's tests — instead of the whole test suite. It
also allows us to classify special tests, like "slow" ones, so that we
can only run them when needed.
2018-06-10 15:33:06 +01:00
Chun-wei Fan
f658e94e65 build: Drop Visual Studio projects
In master, it is already possible to build GLib using Visual Studio
using Meson[1] for some time, so we should focus on maintaining only the
Meson build files for building GLib with Visual Studio.

[1]: There are caveats when building with Visual Studio 2008, namely
     that one needs to use the mt command to embed the manifests that
     are generated with the .exe/DLLs, for all builds, and that in the
     case where the compilation hangs on Visual Studio 2008 x64, as a
     workaround, should stop the build by terminating all cl.exe tasks
     and change the compiler optimization flag from /O2 (full speed) to
     /O1 (optimize for size), due to compiler optimization issues.
2018-06-06 23:54:13 +08:00
Christoph Reiter
3aa23078ac build: Remove the --disable-mem-pools build option and the DISABLE_MEM_POOLS macro
It's mostly not used anymore and doesn't do what it says it does.

The docs state that it affects GList, GSList, GNode, GMemChunks, GSignal,
GType n_preallocs and GBSearchArray while:

* GList, GSList and GNode use GSlice and are not affected
* GMemChunks is gone
* GType npreallocs is ignored

It also states that it can be used to force the usage of g_malloc/g_free,
which is handled by G_SLICE=always-malloc now.

The only places where it's used is in signal handling through GBSearchArray
and in GValueArray (deprecated). Since it's unlikely that anyone wants to
reduce allocation sizes just for those cases remove the build option.
2018-06-02 09:45:55 +02:00
Xavier Claessens
707106c7a5 Fix Windows build errors in valgrind.h
valgrind.h is a verbatim copy taken from Valgrind project. Previously
that file had local changes that got dropped by last update. To avoid
regressing again, do not edit valgrind.h anymore and instead add a
gvalgrind.h wrapper that gets included instead.

This fix 2 errors:
- uintptr_t is not defined when including valgrind.h on mingw.
- MSVC compiler is not supported on amd64-Win64 platform.
2018-05-28 09:22:55 -04:00
Xavier Claessens
2d4b05bbf8 Revert "Fix build error when compiling with mingw"
This reverts commit 00178f8c8e.
2018-05-28 09:22:55 -04:00
Christoph Reiter
01c02ac08b g_usleep: round up the next millisecond on Windows. See #1371
The timer tests expect that a small value for sleep does not result in
no sleep at all. Round up to the next millisecond to bring it more in line
with other platforms.

This fixes the glib/timer tests.

This makes the 'threadtests' time out since that uses small usleeps a lot and
until now didn't wait at all, but now always waits a msec. Reduce the amount
of tests done on Windows to get the runtime down to something reasonable again.

https://bugzilla.gnome.org/show_bug.cgi?id=795569
2018-05-27 09:23:25 +02:00
Xavier Claessens
00178f8c8e Fix build error when compiling with mingw
uintptr_t must be defined when including valgrind.h, just move it as
last include solves the problem.

https://bugzilla.gnome.org/show_bug.cgi?id=796283
2018-05-26 13:09:56 +05:30
Philip Withnall
d388a00028 docs: Fix typo in gsignal.c documentation comment
Spotted by Morten Welinder <mortenw@gnome.org>.

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

https://bugzilla.gnome.org/show_bug.cgi?id=796186
2018-05-17 13:54:46 +01:00
Xavier Claessens
7b8d8835f5 Meson: libintl is a public dependency of glib-2.0
On non-glibc platforms gettext is provided by extra libintl dependency.
We wrongly thought libintl is an internal dependency and applications
needs to explicitly link on it, but turns out that breaks many
applications and with autotools the .pc generated actually has -lintl in
public "Libs:".

https://bugzilla.gnome.org/show_bug.cgi?id=796085
2018-05-15 13:00:44 -04:00
Philip Withnall
e64113bca0 gobject: Add g_autoptr() support for GTypeClass, GEnumClass, GFlagsClass
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=789968
2018-05-15 15:38:33 +01:00
Philip Withnall
cdfc79aae9 gobject: Add g_autoptr() support for GParamSpec
Do not add support for its subtypes, since all their constructors return
GParamSpec*, and g_param_spec_unref() takes a GParamSpec* rather than a
gpointer — adding G_DEFINE_AUTOPTR_CLEANUP_FUNC() for subtypes of
GParamSpec results in compiler warnings about mismatched parameter
types (GParamSpecBoolean* vs GParamSpec*, for example).

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

https://bugzilla.gnome.org/show_bug.cgi?id=796139
2018-05-15 15:34:09 +01:00
Xavier Claessens
b6cb22f32b Meson: Do not build tests with nodelete/Bsymbolic-functions
-z nodelete breaks the libresourceplugin module usage in the resources.c
test, which expects to be able to unload it.

Make the Meson build match what the autotools build does: only pass
glib_link_flags to the headline libraries (glib-2.0, gio-2.0,
gobject-2.0, gthread-2.0, gmodule-2.0) and omit it from all other build
targets.

https://bugzilla.gnome.org/show_bug.cgi?id=788771
2018-05-09 12:52:59 +01:00
Christian Hergert
e924f77736 gtype: improve get_type fast path
The -fstack-protector-strong used in many distributions by default has a
rather drastic slowdown of the fast path in generated _get_type()
functions using G_DEFINE_* macros. The amount can vary by architecture,
GCC version, and compiler flags.

To work around this, and ensure a higher probability that our fast-path
will match what we had previously, we need to break out the slow-path
(registering the type) into a secondary function that is not a candidate
for inlining.

This ensures that the common case (type registered, return the GType id)
is the hot path and handled in the prologue of the generated assembly even
when -fstack-protector-strong is enabled.

https://bugzilla.gnome.org/show_bug.cgi?id=795180
2018-05-09 12:25:06 +01:00
Philip Withnall
9870de442f gobject: Fix a typo in the G_VALUE_LCOPY documentation
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-05-07 20:43:59 +01:00
Philip Withnall
cc4de801c9 gobject: Reimplement g_param_values_cmp() for GParamSpecVariant
The existing implementation was completely incorrect (despite the fix in
commit 566e64a66) — it always compared GVariants by pointer, rather than
by value.

Reimplement it to compare them by value where possible, depending on
their type. The core of this implementation is g_variant_compare(). See
the documentation and tests for further details of the new sort order.

This adds documentation and tests.

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

https://bugzilla.gnome.org/show_bug.cgi?id=795735
2018-05-04 18:17:59 +01:00
Philip Withnall
a06117d062 Revert "Fix the cmp implementation for variant values"
This reverts commit 566e64a660.

This fix went from one broken state to another. The real fix is to use
g_variant_compare(), which is pending review. See bug #795735.

https://bugzilla.gnome.org/show_bug.cgi?id=795735
2018-05-04 17:22:17 +01:00
Matthias Clasen
566e64a660 Fix the cmp implementation for variant values
This was causing g_param_value_defaults to return 1
for GVariant values even when the value is clearly
different from the default.

This was showing up as gtk-builder-tool stripping
non-default values for GtkActionable::action-target
from ui files.
2018-05-02 08:30:59 -04:00
Philip Withnall
1af84aa435 gobject: Fix documentation for G_VALUE_LCOPY
It was previously a copy–paste of G_VALUE_COLLECT, which is wrong,
because it’s the inverse function of G_VALUE_COLLECT. Document that, so
the whole thing is a little less confusing (but by no means perfect).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-04-27 18:44:41 +01:00
Philip Withnall
9b4c50f63d all: Remove trailing newlines from g_message()/g_warning()/g_error()s
All those logging functions already add a newline to any message they
print, so there’s no need to add a trailing newline in the message
passed to them.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-04-27 16:46:19 +01:00
Philip Withnall
16e58dc901 gclosure: Expand documentation and fix some typos
The critical omission from the GClosure documentation is that you need
to call g_closure_set_marshal() when implementing a custom GClosure.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-04-26 18:04:47 +01:00
Kentaro Hayashi
807648663d gobject: Fix redundant warning message in glib-genmarshal
glib-genmarshal shows redundant "time" warning message against combination with --header and --body option.

Before:

  WARNING: Using --header and --body at the same time time is deprecated; use --body --prototypes instead

After:

  WARNING: Using --header and --body at the same time is deprecated; use --body --prototypes instead

https://bugzilla.gnome.org/show_bug.cgi?id=795429
Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
2018-04-23 16:16:36 +01:00
Daniel Boles
042ab215b2 GObject: Clarify 8db5542803 by avoiding double -ve
Make the wording easier to understand by saying what we do, rather than
what we avoid doing if the relevant thing did not happen!
2018-04-22 15:03:03 +01:00
Fabrice Fontaine
b93788ac13 gobject: fix compilation with gcc <= 4.7
On gcc 4.7, we got the following error:

i686-nptl-linux-gnu-gcc --version
> i686-nptl-linux-gnu-gcc (crosstool-NG 1.20.0) 4.7.4
> $ echo '#include <glib-object.h>' | i686-nptl-linux-gnu-gcc -x c -I
staging/usr/include/glib-2.0 -I staging/usr/lib/glib-2.0/include -Wall
-Werror -c - -o /tmp/foo.o
> In file included from
staging/usr/include/glib-2.0/gobject/gbinding.h:29:0,
>                  from staging/usr/include/glib-2.0/glib-object.h:23,
>                  from <stdin>:1:
> staging/usr/include/glib-2.0/gobject/gobject.h: In function
'g_set_object':
> staging/usr/include/glib-2.0/gobject/gobject.h:725:5: error: value
computed is not used [-Werror=unused-value]
> cc1: all warnings being treated as errors

This error has been added by commit 3fae39a5d7
So enable the new g_set_object definition only if gcc >= 4.8

Fixes:
 - http://autobuild.buildroot.net/results/b29a2f868438a2210873ea72f491db63175848be

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=795138
2018-04-20 11:28:42 +01:00