Commit Graph

1969 Commits

Author SHA1 Message Date
Xavier Claessens
9159e84ce5 Windows: Do not link DLL specific resources when doing a static build
Fixes: #2585
2022-01-26 09:49:30 -05:00
Loic Le Page
42c77c7ac7 Enable full-static build on Windows
Glib cannot be built statically on Windows because glib, gobject and gio
modules need to perform specific initialization when DLL are loaded and
cleanup when unloaded. Those initializations and cleanups are performed
using the DllMain function which is not called with static builds.

Issue is known for a while and solutions were already proposed but never
merged (see: https://gitlab.gnome.org/GNOME/glib/-/issues/692). Last
patch is from version 2.36.x and since then the
"constructor/destructor" mechanism has been implemented and used in
other part of the system.

This patch takes back the old idea and updates it to the last version of
glib to allow static compilation on Windows.

WARNING: because DllMain doesn't exist anymore in static compilation
mode, there is no easy way of knowing when a Windows thread finishes.
This patch implements a workaround for glib threads created by calling
g_thread_new(), so all glib threads created through glib API will behave
exactly the same way in static and dynamic compilation modes.
Unfortunately, Windows threads created by using CreateThread() or
_beginthread/ex() will not work with glib TLS functions. If users need
absolutely to use a thread NOT created with glib API under Windows and
in static compilation mode, they should not use glib functions within
their thread or they may encounter memory leaks when the thread finishes.

This should not be an issue as users should use exclusively the glib API
to manipulate threads in order to be cross-platform compatible and this
would be very unlikely and cumbersome that they may mix up Windows native
threads API with glib one.

Closes #692
2022-01-26 10:14:02 +01:00
Sebastian Dröge
3b3022dff1 Merge branch 'doc_sync_signals' into 'main'
Make clear in doc that signals are emitted synchroniously

See merge request GNOME/glib!2423
2022-01-18 08:53:21 +00:00
Alexander Schwinn
28d833a075 Make clear in doc that signals are emitted synchroniously 2022-01-18 08:53:20 +00:00
Emmanuel Fleury
66ebcbced4 Merge tests/gobject/paramspec-test.c into gobject/tests/param.c
Helps issue #1434
2022-01-17 20:43:27 +00:00
Emmanuel Fleury
86fedcfb93 Merge tests/gobject/gvalue-test.c with gobject/tests/value.c
Helps issue #1434
2022-01-12 21:51:05 +01:00
Bilal Elmoussaoui
2f9b3ec6cc paramspec: fix unref annotation 2021-12-30 12:40:47 +00:00
Emmanuel Fleury
c8274a51cd Fix defined but not used warning in gobject/gobject.c
gobject/gobject.c:1189:1: warning: ‘floating_check’ defined but not used
2021-12-17 15:30:18 +01:00
Emmanuel Fleury
ae345e56c2 Distribute cxx test tests/cxx-test.cpp to each module tests directory
tests/cxx-test.cpp is removed and splitted into gio/tests/cxx.cpp,
gmodule/tests/cxx.cpp and gobject/tests/cxx.cpp.

Helps issue #1434
2021-12-14 14:43:03 +01:00
Emmanuele Bassi
1ec331266a Defer GObject::notify during object destruction
Notifying during object destruction is a dubious "feature": objects
might end up recreating a bunch of state just before clearing it;
language bindings might get spurious notifications during garbage
collection runs.

We freeze the notification queue before running the dispose() chain; if
the object was temporarily vivified during dispose, we thaw the
notification queue, otherwise we let the instance clear it when we
finalize it.

See: https://gitlab.gnome.org/GNOME/gjs/-/issues/445
2021-11-29 15:43:59 +00:00
Nishal Kulkarni
1529c2ca4d gobject: Use new g_newa0() function
Replace old `g_newa()` and `memset()` with `g_newa0()`
2021-11-26 12:24:23 +00:00
Nishal Kulkarni
34cf69ef17 gsignal: Use new g_newa0() function
Replace old `g_alloca()` and `memset()` with `g_newa0()`
2021-11-26 12:24:23 +00:00
Sebastian Dröge
c3f4f9c215 Merge branch 'reformat-enums' into 'main'
tests: Reformat mkenums.py slightly to make run-black.sh happy

See merge request GNOME/glib!2342
2021-11-22 13:54:42 +00:00
Philip Withnall
7a8756d247 gobject: Add advice on larger alignment requirements for GObject members
We now guarantee that GObjects will always be allocated at least as
aligned as the basic types. If you want to put an element in your
GObject which has higher alignment requirements, we can’t guarantee it
will be aligned*. If you need it to be aligned, you’ll need to put it on
the heap (aligned appropriately), or add appropriate padding in your
GObject struct.

*Actually, GSlice will guarantee that the whole GObject is aligned to at
least the power of 2 greater than or equal to the size of the GObject,
which means any element in the GObject struct should always be
appropriate aligned if the compiler pads it appropriately. If malloc()
is used, however, it doesn’t make that guarantee, so we can’t make that
guarantee overall.

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

Helps: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
ed553e8e30 gtype: Eliminate -Wcast-align warnings with G_TYPE_CHECK_INSTANCE_CAST
Regardless of the actual alignment of the GTypeInstance in question,
these do a runtime check on the type, so if the type was originally
aligned correctly when allocated, it should be aligned correctly if the
type check succeeds. -Wcast-align is meant to warn about casts between
types, which this isn’t (if the check succeeds).

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

Fixes: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
0749643daa gobject: Assert that GObjects are at least as aligned as basic types
See the reasoning in the patch for why we believe GObjects *are*
(already) as aligned as the basic types.

We want to make this guarantee so that it’s guaranteed to be safe for
people to ignore -Wcast-align warnings for GObjects which contain basic
types. This typically happens with gdouble on 32-bit ARM platforms.

The checks are slightly complicated by the need to support GObjects with
custom constructors. We should expect that a custom construction
function will chain up to g_object_constructor (which calls
g_type_create_instance() as normal), but it’s possible that someone has
done something crazy and uses a custom allocator which doesn’t return
with the same alignment as GSlice. Hand them a warning in that case. If
that is true, the code which uses their custom-constructed GObject can
presumably already deal with the alignment it gets given.

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

Helps: #1231
2021-11-17 11:56:20 +00:00
Philip Withnall
c6dca3459b tests: Reformat mkenums.py slightly to make run-black.sh happy
This should remove some warnings from the CI, making it easier to see
legitimate CI failures.

For example, see https://gitlab.gnome.org/GNOME/glib/-/jobs/1621041.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-17 10:37:07 +00:00
Michael Catanzaro
98e0789fea Merge branch 'weak-refs-docs' into 'main'
gobject: Clarify behaviour of adding weak refs during disposal

See merge request GNOME/glib!2255
2021-10-27 23:37:22 +00:00
Philip Withnall
2423419a29 Merge branch 'static-analysis' into 'main'
fix issues found by svace static code analyzer

See merge request GNOME/glib!2285
2021-10-18 11:03:33 +00:00
Egor Bychin
5419228f63 gtype: Fix pointer being dereferenced despite NULL check 2021-10-15 14:15:43 +03:00
Philip Withnall
a4c9049486 build: Don’t pass false to install_dir
This fixes a Meson deprecation warning which appeared in Meson 0.50.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-10-07 17:15:13 +01:00
Simon McVittie
6ccb387197 Merge branch 'object-weak-ref-docs' into 'main'
gobject: Document it’s unsafe to call g_object_ref() from GWeakNotify

See merge request GNOME/glib!2246
2021-09-28 09:24:47 +00:00
Philip Withnall
579ff9f6c9 Merge branch 'ebassi/floating-warning' into 'main'
Add a (diagnostic) warning for finalized floating objects

Closes #2489

See merge request GNOME/glib!2247
2021-09-21 11:09:16 +00:00
Marco Trevisan (Treviño)
468246bb3b gobject: Ensure an object has toggle references before notifying it
When an object with toggle reference is notifying a change we just
assume that this is true because of previous checks.
However, while locking, another thread may have removed the toggle
reference causing the waiting thread to abort (as no handler is set at
that point).

To avoid this, once we've got the toggle references mutex lock, check
again if the object has toggle reference, and if it's not the case
anymore just ignore the request.

Add a test that triggers this, it's not 100% happening because this is
of course timing related, but this is very close to the truth.

Fixes: #2394
2021-09-20 17:56:25 +02:00
Philip Withnall
3f1a1cdb78 Merge branch 'prop-set-speedups' into 'main'
Small optimization for g_object_set

See merge request GNOME/glib!2254
2021-09-20 12:47:00 +00:00
Philip Withnall
3b67d53227 gobject: Clarify behaviour of adding weak refs during disposal
The previous wording was not clear about what happens if a new weak ref
is taken during disposal (shortly after resurrecting the object with a
new strong ref, otherwise taking the weak ref is invalid).

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2064/diffs#note_1270092

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

Helps: #2390
2021-09-20 13:23:34 +01:00
Matthias Clasen
497986cdc1 Small optimization for g_object_setv
No need to call memset in the loop, we can just
initialize all the values in one go.

GtkBuilder is now using g_object_setv, so this
may improve application start times a bit.
2021-09-20 08:21:49 -04:00
Matthias Clasen
23e37e05d2 Small optimization for g_object_set
We've already followed the redirection, no need
to check for that again - just avoid notifying
non-readable properties.
2021-09-20 08:21:42 -04:00
Marco Trevisan (Treviño)
a7262d6357 gobject: Cleanup weak locations data as part of dispose
Weak locations were not fully cleaned on run_dispose() and after dispose
vfunc was called, so ensure that this is the case.

Fixes: #865
2021-09-17 12:28:01 +02:00
Marco Trevisan (Treviño)
e861f60dcb gobject: Cleanup weak locations when the last one has been removed
As per the previous change, an object that had weak locations set may
need to lock again the weak locations mutex during qdata cleanup, but
we can avoid this when we know we're removing the last location, by
removing the qdata entry and freeing the data.

In case a new location is needed for the same object, new data will be
added.

However, by doing this the weak locations during dispose may be
invalidated once the weak locations lock is passed, so check again if
this is the case while removing them.
2021-09-17 12:27:59 +02:00
Marco Trevisan (Treviño)
ea68b22135 gobject: Cleanup GWeakRef locations on object finalization
It can happen that a GWeakRef is added to an object while it's disposing
(or even during finalizing) and this may happen in a thread that (weak)
references an object while the disposal isn't completed yet or when
using toggle references and switching to GWeakRef on notification (as
the API suggests).

In such scenario the weak locations are not cleaned up when the object
is finalized, and will point to a free'd area.

So, during finalization and when we're sure that the object will be
destroyed for sure, check again if there are new weak locations and
unset them if any as part of the qdata destruction.
Do this adding a new utility function so that we can avoid duplicating
code to free the weak locations.

Added various tests simulating this case.

Fixes: #2390
2021-09-17 12:21:23 +02:00
Philip Withnall
0d57092a03 gobject: Document it’s unsafe to call g_object_ref() from GWeakNotify
The documentation sort of already said this, but it’s better to make it
explicit.

This avoids the situation where some of the weak notify callbacks for an
object have been called, and then a subsequent one resurrects the
object. Without some way of undoing the weak notifications already sent,
that would leave external state which is coupled to the object’s
lifecycle out of sync.

This arose from discussion on !2064.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-09-15 15:02:47 +01:00
Emmanuele Bassi
6fe0f98360 Add a (diagnostic) warning for finalized floating objects
GTK currently checks if a GtkWidget is finalized while still using a
floating reference—i.e. a widget was disposed without any parent
container owning it.

This warning can be useful to identify and trace ownership transfer
issues in libraries using initially unowned floating object types.

To avoid introducing constraints ex post, we can gate this check behind
both the G_ENABLE_DEBUG compile time flag for GLib, and behind the
G_ENABLE_DIAGNOSTIC environment variable run time check.

Fixes: #2489
2021-09-14 16:09:22 +01:00
Philip Withnall
e99ee3588a Merge branch 'revert-cd93c350' into 'main'
Revert "Merge branch 'fix/gclosure-invoke-type-annotation' into 'main'"

Closes #2477

See merge request GNOME/glib!2237
2021-09-06 15:23:54 +00:00
DarkTrick
3c459b7fd6 doc: Explicitly said, that no null term. is needed 2021-09-06 11:23:14 +00:00
Evan Welsh
0de8ec87d2 Revert "Merge branch 'fix/gclosure-invoke-type-annotation' into 'main'"
This reverts merge request !2181
2021-08-29 20:56:08 +00:00
Philip Withnall
709df8eeb4 Merge branch 'docgen-fixes' into 'main'
Adapt documentation to gi-docgen

See merge request GNOME/glib!2206
2021-08-03 13:53:38 +00:00
Emmanuele Bassi
f62622fc7b docs: Start stanzas with a single paragraph
When rendering the contents of the GLib documentation stored inside the
introspection data, a common behaviour is to take the first paragraph as
a summary of the symbol being documented.

The documentation is assumed to be in Markdown format, which means:

 - paragraphs must be separated by newlines
 - lines that have an indentation of four or more spaces are considered
   code blocks
 - lines that start with a `#` are considered titles

This means we need to slightly tweak the documentation in our sources to
ensure that it can be rendered appropriately by tools that are not
gtk-doc.

See issue: #2365
2021-08-02 13:22:23 +01:00
Matthias Clasen
6a6da9637a Fix a Unicode typo
The name of one of the Unicode Break types is misspelt.
Add an alias, since it annoys me every time I look at
Pango's break code.
2021-07-29 10:09:27 -04:00
Emmanuele Bassi
9aacb4dd6f Add unit for the "final" GType flag
Check that we're emitting the correct set of warnings when trying to
derive a final type.
2021-07-27 12:27:53 +01:00
Emmanuele Bassi
d1861c8fda Add G_DEFINE_* macros for final types
These should match the G_DECLARE_FINAL_* macros used in a header file.
2021-07-26 20:13:32 +01:00
Emmanuele Bassi
c07dd416cf gtype: Add a "final" flag
We want to have the ability to mark types that should not be derivable
even if they are in a deeply derivable type hierarchy; in other words,
leaf nodes in the types tree.
2021-07-26 20:13:32 +01:00
GOUJON Évan
6e46edea5b gobject/tests/param: Fix a memory leak 2021-07-23 22:21:33 +02:00
Philip Withnall
950bbe7984 Merge branch 'DarkTrick-main-patch-15325' into 'main'
Update GValue doc: How to use GBoxed with GValue

See merge request GNOME/glib!2179
2021-07-22 12:37:43 +00:00
DarkTrick
94644e9b59 Update GValue doc: How to use GBoxed with GValue 2021-07-22 13:21:35 +01:00
DarkTrick
ea365b7ea6 g_boxed_type_register_static: added reference to G_DEFINE_BOXED_TYPE 2021-07-22 12:16:41 +00:00
DarkTrick
80189ca892 Clarify GValue documentation 2021-07-12 10:40:33 +00:00
Ole André Vadla Ravnås
9c01c1ebee gclosure: Fix the invoke() return_value annotation
The return value must be initialized by the caller, as is clear from
GLib's internal callers, and e.g. dummy_closure_marshal() on the callee
side.
2021-07-09 02:43:54 +02:00
DarkTrick
1fc905efe4 g_value_set_string description: clarified (unified), that v_string is a copy. 2021-06-23 05:50:59 +00:00
Philip Withnall
b95d9d1db6 Merge branch 'g_obj_take_ref' into 'main'
GObject: add g_object_take_ref()

Closes #1112

See merge request GNOME/glib!2146
2021-06-15 11:28:00 +00:00
Allison Ryan Lortie
3764c6730e GObject: add g_object_take_ref()
This works in the same way as g_variant_take_ref(), and for the same
reason.

Updated and Rebased by Nitin Wartkar <nitinwartkar58@gmail.com>

Closes #1112
2021-06-11 18:13:34 +05:30
Philip Withnall
c0fe89c986 Merge branch 'gtypeof' into 'main'
glib_typeof: Move definition to its own header

See merge request GNOME/glib!1969
2021-06-10 12:26:27 +00:00
Jasper St. Pierre
edb40c7171 gobject: Allow passing %NULL for @data in g_object_remove_toggle_ref
gjs has some situations where it's not always aware of the @data that
was passed into g_object_add_toggle_ref, so allow passing %NULL to
just match on @notify.

Rebased and updated by Nitin Wartkar

Closes #817
2021-05-27 21:09:45 +05:30
Emmanuel Fleury
bee07cebcd Fix missing initializer warning in gobject/gtype.c
gobject/gtype.c:1103:55: warning: missing field 'value_free' initializer
          static const GTypeValueTable zero_vtable = { NULL, };
                                                             ^
2021-05-27 10:16:52 +02:00
Xavier Claessens
090d65712d glib_typeof: Move definition to its own header
It is cleaner to define glib_typeof() in a header included after
gversionmacros.h so we can use GLIB_VERSION_MIN_REQUIRED directly
instead of doing it everywhere glib_typeof() is used.
2021-05-17 12:07:30 -04:00
Philip Withnall
7e9585177d tests: Drop use of g_test_bug_base()
Include the base URI in the `g_test_bug()` calls instead. This resolves
inconsistencies between the old bug base (bugzilla.gnome.org) and the
new bug base (gitlab.gnome.org). It also has the advantage that the URI
passed to `g_test_bug()` is now clickable in the code editor, rather
than being split across two locations.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/275#note_303175

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-13 22:16:27 +01:00
Sebastian Dröge
730cc864ef Merge branch 'jomccambridge-master-patch-47329' into 'master'
Update signal accumulator docs.

Closes #2352

See merge request GNOME/glib!2058
2021-05-06 14:00:19 +00:00
Nishal Kulkarni
98050b756b gtype: use G_GNUC_CHECK_VERSION
Replace `__GLIBC__` with `G_GNUC_CHECK_VERSION`
2021-04-29 17:40:14 +05:30
John McCambridge
e010624309 Update signal accumulator docs.
Reflect that a FALSE returned from the accumulator will still emit signals in the RUN_CLEANUP state.
Fixes #2352
2021-04-29 09:41:44 +01:00
Marco Trevisan (Treviño)
b8a9f4b436 boxed: Register GPatternSpec as boxed type 2021-04-27 16:25:09 +02:00
Philip Withnall
856aeba9e4 glib-mkenums: Parse and skip deprecation/availability annotations
Teach `glib-mkenums` how to parse and ignore:
 - `GLIB_AVAILABLE_ENUMERATOR_IN_x_xx`
 - `GLIB_DEPRECATED_ENUMERATOR_IN_x_xx`
 - `GLIB_DEPRECATED_ENUMERATOR_IN_x_xx_FOR(x)`

Future work could expose the deprecation/availability information as
substitutions in the template file, but this commit does not do that.

It does, however, add some unit tests for the annotations.

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

Fixes: #2327
2021-03-11 13:37:49 +00:00
Aleksandr Mezin
f346b9c8ce glib-genmarshal: close output file
Close output file to ensure all buffered output actually gets written.

Otherwise, glib-genmarshal output is sometimes empty (for example, when trying
to build gdk-pixbuf on Windows, with Meson installed from .msi package).

argparse.FileType doesn't get closed automagically when the script exits:
https://bugs.python.org/issue13824

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2341
2021-03-03 12:24:29 +06:00
Iain Lane
552b8fd862
glib/gmacros.h: Move <type_traits> include to consumers
When included inside an `extern "C"` block, this causes build failures
that look something like:

  /usr/include/c++/10/type_traits:2930:3: error: template with C linkage
   2930 |   template<typename _Fn, typename... _Args>
        |   ^~~~~~~~
  ../../disas/arm-a64.cc:20:1: note: ‘extern "C"’ linkage started here
     20 | extern "C" {
        | ^~~~~~~~~~

Commit 4273c43902 made this opt in for
projects which are defining `GLIB_VERSION_MIN_REQUIRED`, but the include
of `<type_traits>` via `gmacros.h` was not included in this. If we move
the include out to the places where `glib_typeof` is called, we can make
it covered by this macro too, and save a few consumers from FTBFSing.

That also means that, if you don't want to fix your use of the headers,
and as long as this version is sufficient for you, a quick workaround is
to define `GLIB_VERSION_MIN_REQUIRED` to `GLIB_VERSION_2_66` or lower.

Suggested by Simon McVittie.

Alternative to: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1935
Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2331
2021-02-25 15:33:59 +00:00
Philip Withnall
f10101b909 gobject: Use g_memdup2() instead of g_memdup() in obvious places
Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
2021-02-04 14:13:21 +00:00
Sebastian Dröge
e38982df4b Merge branch 'atomic-typeof' into 'master'
Define glib_typeof with C++11 decltype()

Closes #2226

See merge request GNOME/glib!1715
2021-02-02 10:51:50 +00:00
Thomas Haller
8416211231 gsignal: use g_clear_signal_handler() macro to implement g_clear_signal_handler() function
We have a "good" implementation of g_clear_signal_handler() in
form of a macro. Use it, and don't duplicate the code.

Also add a comment to the documentation that "instance" in fact must
not point to a valid GObject instance -- if the handler ID is unset.

Also reword the documentation about the reasoning for why a macro
version exists. The reason is not to use the function "without
pointer cast". I don't think the non-macro version requires any
pointer cast, since "instance" is a void pointer. Was this referring
to the handler_id_ptr? That doesn't seem right either, because the
caller should always provide a "gulong *" pointer and nothing else.
2021-02-01 09:45:46 +01:00
Thomas Haller
7777f3bdbe gsignal: let g_clear_signal_handler() evaluate argument only once
Preferably macros behave function-like to minimize surprises. That
means for example that they evaluate all arguments exactly once.

Rework g_clear_signal_handler() to assign the macro parameters
to auto variables so they are accessed exactly once.

Also, drop the static assert for the size of (*handler_id_ptr).
As we now assign to a "gulong *" pointer, the compiler already
checks the types. In fact, the check is now stricter than before.
Previously it would have allowed a pointer to a "signed long".
This is a change in behavior of the macro and the stricter compile
check could cause a build failure with broken code.

Also, clear the handler id first, before calling
g_signal_handler_disconnect(). Disconnecting a signal invokes the
destroy notify, which can have side effects. It just feels cleaner
to first reset the *_handler_id_ptr, before those side effects
can happen. Of course, in practice it makes little difference.
2021-02-01 09:45:16 +01:00
Thomas Haller
cc4ffe4742 gsignal: use stack allocate temporary buffer in g_signal_new_valist()
g_signal_new_valist() is called by g_signal_new(), which is probably
the most common way to create a signal.

Also, in almost all cases is the number of signal parameters small.

Let's optimize for that by using a stack allocated buffer if we have
few parameters.
2021-02-01 09:43:29 +01:00
Xavier Claessens
4273c43902 glib_typeof: It is an API break that should be opt-in
That changes the return type of functions like g_object_ref() that can
break C++ applications like Webkit. Note that it is not an ABI break.

It must thus be opt-in the same way we did when adding this to
g_object_ref() for GNU C compilers in the first place. Unfortunately it
cannot be done directly in gmacros.h because GLIB_VERSION_2_68 is not
defined there, and gversionmacros.h cannot be included there because
there is some strict ordering in which those headers must be included.

This means that applications that does not define
GLIB_VERSION_MIN_REQUIRED will still get an API break, so we encourage
them to declare their minimum requirement to avoir such issues in the
future too.
2021-01-27 09:26:39 -05:00
Philip Withnall
d4a875d8cd gtype: Improve formatting of GType documentation
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-20 15:42:55 +00:00
Emmanuele Bassi
8199fd65a9 Merge branch '2227-gobject-annotation-fixes' into 'master'
Add more GIR annotations to gparam.c and gsignal.c

See merge request GNOME/glib!1804
2021-01-19 11:35:15 +00:00
Emmanuele Bassi
e97ebfe628 Fix the transfer annotations for GClosure constructors
The GClosure constructors in GObject return an instance with a floating
reference.

Fixes: #2299
2021-01-19 11:36:01 +02:00
Matthias Klumpp
1261461840 mkenums: Support public/private trigraphs again
This change was previously implemented in
9ba17d511e but got dropped during the
Python conversion of the Perl script.

See the commit message of this commit as well as
https://bugzilla.gnome.org/show_bug.cgi?id=782162
for more information.
This patch also adds a new test so we don't loose this feature again.
2021-01-10 20:51:54 +01:00
Matthias Klumpp
ca28a3fc29 trivial: Formatting changes 2021-01-10 18:59:45 +01:00
Timm Bäder
423bfa87d5 gparam: Remove pspec_list_remove_overridden_and_redirected()
Instead of collecting more pspecs than we need, just don't add them to
the list(s) in the first place.
2020-12-31 14:58:34 +01:00
Sebastian Dröge
3581eda9a2 gsignal: Allow return types for RUN_FIRST-only signals too
Also adds a test that checks that the G_SIGNAL_RUN flags are handled
correctly and the class signal handler is called at the right times.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/513
2020-12-21 17:22:51 +00:00
Sebastian Dröge
9d1455444c gsignal: Add a new GSignalFlag to mark the first run of an accumulator function
Also add a test for signal accumulators. There was none before, and this
one now also covers the new flag.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/514
2020-12-21 17:10:19 +00:00
Emmanuel Fleury
6ca38ccdd4 Fix missing initializer warning in gobject/tests/ifaceproperties.c:base_object_get_type()
gobject/tests/ifaceproperties.c: In function ‘base_object_get_type’:
gobject/tests/ifaceproperties.c:321:1: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
  321 | static DEFINE_TYPE_FULL (BaseObject, base_object,
      | ^~~~~~
In file included from gobject/gobject.h:24,
                 from gobject/gbinding.h:29,
                 from glib/glib-object.h:22,
                 from gobject/tests/ifaceproperties.c:21:
gobject/gtype.h:1063:26: note: ‘value_table’ declared here
 1063 |   const GTypeValueTable *value_table;
      |                          ^~~~~~~~~~~
2020-12-16 23:59:17 +01:00
Emmanuel Fleury
ff5d09af5e Fix missing initializer warning in gobject/tests/ifaceproperties.c:test_iface_get_type()
gobject/tests/ifaceproperties.c: In function ‘test_iface_get_type’:
gobject/tests/ifaceproperties.c:144:1: error: missing initializer for field ‘class_finalize’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
  144 | static DEFINE_IFACE (TestIface, test_iface, NULL, test_iface_default_init)
      | ^~~~~~
In file included from gobject/gobject.h:24,
                 from gobject/gbinding.h:29,
                 from glib/glib-object.h:22,
                 from gobject/tests/ifaceproperties.c:21:
gobject/gtype.h:1054:26: note: ‘class_finalize’ declared here
 1054 |   GClassFinalizeFunc     class_finalize;
      |                          ^~~~~~~~~~~~~~
2020-12-16 23:57:08 +01:00
Emmanuel Fleury
805053d09b Fix signedness warning in gobject/tests/signals.c:test_introspection()
gobject/tests/signals.c: In function ‘test_introspection’:
gobject/tests/signals.c:1180:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1180 |   for (i = 0; i < n_ids; i++)
      |                 ^
2020-12-16 23:26:34 +01:00
Emmanuel Fleury
176b204754 Fix signedness warnings in gobject/tests/properties.c:properties_get_property()
gobject/tests/properties.c: In function ‘properties_get_property’:
gobject/tests/properties.c:562:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  562 |   for (i = 0; i < G_N_ELEMENTS (test_props); i++)
      |                 ^
gobject/tests/properties.c:583:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  583 |   for (i = 0; i < G_N_ELEMENTS (test_props); i++)
      |                 ^
2020-12-16 23:26:34 +01:00
Philip Withnall
db70edb6ec Merge branch 'fix_more_warnings' into 'master'
Fix more warnings

See merge request GNOME/glib!1773
2020-12-16 11:45:41 +00:00
Emmanuel Fleury
8fb696e003 Fix missing initializer warning in gobject/tests/dynamictests.c:test_module_get_type()
gobject/tests/dynamictests.c: In function ‘test_module_get_type’:
gobject/tests/dynamictests.c:97:7: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
   97 |       };
      |       ^
In file included from gobject/gobject.h:24,
                 from gobject/gbinding.h:29,
                 from glib/glib-object.h:22,
                 from gobject/tests/dynamictests.c:23:
gobject/gtype.h:1063:26: note: ‘value_table’ declared here
 1063 |   const GTypeValueTable *value_table;
      |                          ^~~~~~~~~~~
2020-12-16 10:56:32 +01:00
Emmanuel Fleury
34cb225543 Fix missing initializer warning in gobject/gparam.c:g_param_type_register_static()
gobject/gparam.c: In function ‘g_param_type_register_static’:
gobject/gparam.c:1434:3: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘struct _GTypeInfo’}
 1434 |   };
      |   ^
In file included from gobject/gvalue.h:26,
                 from gobject/gparam.h:26,
                 from gobject/gparam.c:26:
gobject/gtype.h:1063:26: note: ‘value_table’ declared here
 1063 |   const GTypeValueTable *value_table;
      |                          ^~~~~~~~~~~
2020-12-16 10:56:32 +01:00
Emmanuel Fleury
dd16d1e879 Fix missing initializer warning in gobject/gtypemodule.c:g_type_module_get_type()
gobject/gtypemodule.c: In function ‘g_type_module_get_type’:
gobject/gtypemodule.c:154:7: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
  154 |       };
      |       ^
In file included from gobject/gtypeplugin.h:24,
                 from gobject/gtypemodule.c:22:
gobject/gtype.h:1063:26: note: ‘value_table’ declared here
 1063 |   const GTypeValueTable *value_table;
      |                          ^~~~~~~~~~~
2020-12-16 10:56:32 +01:00
Emmanuel Fleury
12ec1eb062 Fix missing initializer warning in gobject/gtypeplugin.c:g_type_plugin_get_type()
gobject/gtypeplugin.c: In function ‘g_type_plugin_get_type’:
gobject/gtypeplugin.c:91:7: error: missing initializer for field ‘class_init’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
   91 |       };
      |       ^
In file included from gobject/gtypeplugin.h:24,
                 from gobject/gtypeplugin.c:20:
gobject/gtype.h:1053:26: note: ‘class_init’ declared here
 1053 |   GClassInitFunc         class_init;
      |                          ^~~~~~~~~~
2020-12-16 10:56:32 +01:00
Emmanuel Fleury
cc7540909f Fix signedness warning in gobject/gtype.c:iface_node_has_available_offset_L()
gobject/gtype.c: In function ‘iface_node_has_available_offset_L’:
gobject/gtype.c:1288:42: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘int’
 1288 |   if (G_ATOMIC_ARRAY_DATA_SIZE (offsets) <= offset)
      |                                          ^~
2020-12-16 10:56:24 +01:00
Philip Withnall
39f33412db python: Reformat some files to keep style-check-diff happy
The version of `black` on the CI server wanted these changes. Make them
to keep the `style-check-diff` CI job from constantly failing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:40:57 +00:00
Philip Withnall
7ad0c3a0f4 gsignal: Add (closure) and (destroy) annotations
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:08:40 +00:00
Philip Withnall
d2cd34969a gparam: Fix transfer annotation for g_param_spec_internal()
`GParamSpec`s are floating by default.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 17:59:45 +00:00
Philip Withnall
181a12c393 gsignal: Add missing (transfer) and (nullable) return annotations
This commit only looks at the `Returns:` lines in the documentation, and
has examined all of them in the file. Function arguments have not been
checked.

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

Helps: #2227
2020-12-11 23:49:30 +00:00
Philip Withnall
c7a7dd9ae3 gparam: Add missing (transfer) and (nullable) return annotations
This commit only looks at the `Returns:` lines in the documentation, and
has examined all of them in the file. Function arguments have not been
checked.

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

Helps: #2227
2020-12-11 23:49:14 +00:00
Philip Withnall
a9e3e3715a genums: Add missing (transfer) and (nullable) return annotations
This commit only looks at the `Returns:` lines in the documentation, and
has examined all of them in the file. Function arguments have not been
checked.

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

Helps: #2227
2020-12-11 23:48:35 +00:00
Sebastian Dröge
e82eb490fe Handle the case of g_object_run_dispose() in GBinding
When this is called on the source or target, the weak notify of the
corresponding object is called without the GWeakRef being cleared.
See https://gitlab.gnome.org/GNOME/glib/-/issues/2266 for that issue.

This means that a strong reference to these zombie objects can be
retrieved from the GWeakRefs and the previous assumption that this can't
happen was wrong. Remove the assertion for that accordingly and handle
this case.

Specifically, all signal handlers and weak notifies of the object are
already gone and must not be disconnected/removed a second time, or
otherwise memory corruption would be caused. Instead just set the
GWeakRef to NULL and handle it otherwise as if the GWeakRef didn't give
a strong reference to begin with.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2265
2020-12-08 18:41:27 +02:00
Sebastian Dröge
a2de4b2479 Clarify in g_object_weak_ref() docs that the callback is called during disposing and not finalizing
This especially has the effect that any GWeakRefs to the object will not
necessarily be set to NULL yet if called as part of
g_object_run_dispose() and not as part of g_object_unref().
2020-12-08 18:09:50 +02:00
Emmanuel Fleury
bbb9ef19ce Fix signedness warnings in gobject/tests/value.c:test_valuearray_basic()
gobject/tests/value.c: In function ‘test_valuearray_basic’:
gobject/tests/value.c:253:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  253 |   for (i = 0; i < a->n_values - 1; i++)
      |                 ^
gobject/tests/value.c:257:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  257 |   for (i = 0; i < a->n_values; i++)
      |                 ^
2020-12-05 17:11:55 +01:00
Philip Withnall
5e1d368eec Merge branch 'binding-threadsafe-2' into 'master'
Make GBinding thread-safe (alternative approach)

See merge request GNOME/glib!1745
2020-12-04 14:23:10 +00:00
Sebastian Dröge
52261f0abe Deprecate g_binding_get_source() and get_target() in favour of dup_source() and dup_target()
The old functions are not thread-safe by design.
2020-11-26 19:51:56 +02:00
Sebastian Dröge
7367c5d367 Release GBinding transform functions also when implicitly unbinding because source/target are finalized
This was inconsistently handled before and only explicit unbinding or
finalizing the binding would've previously released the transform
function. If the source/target were finalized while more strong
references to the binding still existed then the transform function
would stay alive and only the binding itself would be deactivated.
2020-11-26 19:51:56 +02:00
Sebastian Dröge
cc15c933b3 Add tests for GBinding thread-safety 2020-11-26 19:51:56 +02:00