31383 Commits

Author SHA1 Message Date
Thomas Haller
1c9d54d4ea gobject/performance: normalize base factors for test runs
When running the test (without parameters), it estimates a factor for
the run size for each test. That is useful for running a reasonable size
of the test, on different machines.

However, when comparing two runs, it seems important that both runs
share a common factor. Otherwise, the factor is determined differently,
and the test is less comparable. For that there is the "--factor" option
or the GLIB_PERFORMANCE_FACTOR environment variable.

However, the factor option can only set the factors for all tests at the
same time. Optimally, one factor is roughly suitable for all tests, but
it is not, as currently the detected factors on my machine are widely
different

  $ ./build/gobject/tests/performance/performance -v > p
  $ cat p | sed -n -e 's/^Running test //p' -e 's/.*correction factor //p' | sed 'N;s/\n/ /'
  simple-construction 34.78
  simple-construction1 145.45
  complex-construction 11.08
  complex-construction1 20.46
  complex-construction2 23.74
  finalization 4.74
  type-check 37.74
  emit-unhandled 5.63
  emit-unhandled-empty 49.69
  emit-unhandled-generic 7.17
  emit-unhandled-generic-empty 50.63
  emit-unhandled-args 5.20
  emit-handled 3.86
  emit-handled-empty 4.01
  emit-handled-generic 3.96
  emit-handled-generic-empty 7.04
  emit-handled-args 3.78
  notify-unhandled 52.63
  notify-by-pspec-unhandled 156.86
  notify-handled 2.55
  notify-by-pspec-handled 2.66
  property-set 34.63
  property-get 32.92
  refcount 0.83
  refcount-1 2.30
  refcount-toggle 1.33

Adjust the base factors with these measurements.

  PERFORMANCE_FILE="./gobject/tests/performance/performance.c"
  IFS=$'\n'
  for LINE in $(cat p | sed -n -e 's/^Running test //p' -e 's/.*correction factor //p' | sed 'N;s/\n/ /') ; do
    (
      IFS=' '
      set -- $LINE
      TESTNAME="$1"
      FACTOR="$2"

      LINENUMBER="$(grep -n "^    \"$TESTNAME\",$" "$PERFORMANCE_FILE" | cut -d: -f1)"
      LINENUMBER=$((LINENUMBER + 2))

      OLD_FACTOR="$(sed -n "$LINENUMBER s/^    \([0-9]\+\),$/\1/p" "$PERFORMANCE_FILE")"

      NEW_FACTOR="$(awk -v factor="$FACTOR" -v old_factor="$OLD_FACTOR" 'BEGIN {print int(factor * old_factor + 0.5)}')"

      sed -i "$LINENUMBER s/^    \([0-9]\+\),$/    $NEW_FACTOR,/" "$PERFORMANCE_FILE"
    )
  done

Afterwards, we get comparable factors:

  $ ./build/gobject/tests/performance/performance -v > p2
  $ cat p2 | sed -n -e 's/^Running test //p' -e 's/.*correction factor //p' | sed 'N;s/\n/ /'
  simple-construction 0.98
  simple-construction1 0.75
  complex-construction 0.99
  complex-construction1 0.96
  complex-construction2 1.02
  finalization 1.05
  type-check 0.98
  emit-unhandled 1.01
  emit-unhandled-empty 1.10
  emit-unhandled-generic 1.03
  emit-unhandled-generic-empty 1.07
  ...

Of course, this measurement was taken in my setup.  But I think it
brings the base factors into a comparable range for most users.

Also, the commit message shows an ugly script how you can re-generate
this for your own purposes.
2025-02-26 12:22:24 +01:00
Thomas Haller
0e1597ffb9 gobject/performance: rework setting the base factor for number of rounds
Move the factor inside the PerformanceTest structure, so it can be
programatically accessed.

More importantly, the number is now expressed directly beside the test
setup (the PerformanceTest structure), all at one place.

Also, each test now gets a separate factor.

This change will be useful in the next commit. So far there is no
notable change in behavior.
2025-02-26 12:22:24 +01:00
Thomas Haller
6a231008e4 gobject/performance: fix "type-check" test to not optimize out test code
Despite assigning the function to a variable, gcc can still detect that
the function never changes and most of the test code is optimized out.
Initialize it somewhere, where the compiler cannot prove that this
function pointer is always set to the same value.

We could also make the pointer volatile, but this approach seems
preferable to me.
2025-02-26 12:22:24 +01:00
Philip Withnall
2cee7809d1 Merge branch 'main' into 'main'
Update Georgian translation

See merge request GNOME/glib!4511
2025-02-25 14:47:46 +00:00
Philip Withnall
1438e1c12e Merge branch 'translation' into 'main'
Update Chinese translation

See merge request GNOME/glib!4518
2025-02-25 09:44:59 +00:00
lumingzh
74ec63e29e update Chinese translation 2025-02-25 01:16:33 +00:00
Philip Withnall
3f323fe94f Merge branch 'main' into 'main'
doc: point to iconv(3) and iconv(3posix) for more details about iconv

See merge request GNOME/glib!4515
2025-02-25 00:56:09 +00:00
Reuben Thomas
5fc4248b74 doc: point to iconv(3) and iconv(3posix) for more details about iconv
The documentation in GLib of iconv is forgivably brief. Advanced users (e.g.
for streaming use, for which this API is recommended over the simpler GLib
APIs) will want to know more detail about what happens when there’s an
error: without knowing, you can’t really use this function for streaming.

Point to both iconv(3posix), which gives the fully-portable details, i.e.
all that a user of GLib can rely on, and iconv(3), which is rather easier to
read, and may be of interest to those writing GNU-specific code, or who know
that their GLib is built with libiconv.

The API already promises that it’s the “[s]ame as the standard UNIX routine
iconv()”, so it’s quite safe to point to the relevant man pages; looking at
the source code bears this out, as g_iconv merely calls iconv.
2025-02-25 00:56:07 +00:00
Philip Withnall
87dfae2246 Merge branch 'update_uk1' into 'main'
Update Ukrainian translation

See merge request GNOME/glib!4514
2025-02-24 23:54:57 +00:00
Philip Withnall
a0c5f5a9fb Merge branch 'main' into 'main'
Update Bulgarian translation

See merge request GNOME/glib!4516
2025-02-24 23:54:47 +00:00
Philip Withnall
f49674d4fd Merge branch 'Persian' into 'main'
Update file fa.po

See merge request GNOME/glib!4517
2025-02-24 23:50:50 +00:00
Philip Withnall
d9cd99f9b4 Merge branch 'th/gobject-inline-private-call' into 'main'
[th/gobject-inline-private-call] gobject: avoid GLIB_PRIVATE_CALL() for g_datalist_id_update_atomic

See merge request GNOME/glib!4513
2025-02-24 23:47:22 +00:00
Danial Behzadi
33528d2e8c Update file fa.po 2025-02-24 20:34:41 +00:00
Alexander Shopov
5b4d8c28ab Update Bulgarian translation
Originally from https://l10n.gnome.org/vertimus/glib/main/po/bg/
2025-02-24 21:07:22 +01:00
Thomas Haller
482e078083 gobject: avoid GLIB_PRIVATE_CALL() for g_datalist_id_update_atomic()
Cache the function pointer for g_datalist_id_update_atomic() in a static
variable in "gobject.c" to avoid looking it up repeatedly.

g_datalist_id_update_atomic() is anyway internal API. Like GData is not
a useful data structure in general, this function is only useful for
something specific inside GObject.

It can be easily seen that _local_g_datalist_id_update_atomic is never
read without having a GObject at hand (because we call it on
`&object->qdata`). Thus initializing the pointer in
g_object_do_class_init() (under lock) is sufficient to ensure
thread-safe initialization. Note that we still set the pointer via
g_atomic_pointer_set(). This is done in an attempt to pacify thread
sanatizer.

Note that also with LTO enabled, the GLIB_PRIVATE_CALL() call cannot be
inlined. Previously we get:

0000000000011300 <_weak_ref_set>:
   ...
   1131d:       e8 ee 03 ff ff          call   1710 <glib__private__@plt>
   11322:       8b 35 0c b2 05 00       mov    0x5b20c(%rip),%esi        # 6c534 <quark_weak_locations.lto_priv.0>
   11328:       4c 89 e1                mov    %r12,%rcx
   1132b:       49 8d 7c 24 10          lea    0x10(%r12),%rdi
   11330:       48 8d 15 b9 42 ff ff    lea    -0xbd47(%rip),%rdx        # 55f0 <weak_ref_data_get_or_create_cb.lto_priv.0>
   11337:       ff 90 80 00 00 00       call   *0x80(%rax)

afterwards:

0000000000011300 <_weak_ref_set>:
   ...
   1131d:       48 8d 7e 10             lea    0x10(%rsi),%rdi
   11321:       48 89 f1                mov    %rsi,%rcx
   11324:       48 8d 15 c5 42 ff ff    lea    -0xbd3b(%rip),%rdx        # 55f0 <weak_ref_data_get_or_create_cb.lto_priv.0>
   1132b:       8b 35 0b b2 05 00       mov    0x5b20b(%rip),%esi        # 6c53c <quark_weak_locations.lto_priv.0>
   11331:       ff 15 f9 b1 05 00       call   *0x5b1f9(%rip)        # 6c530 <_local_g_datalist_id_update_atomic.lto_priv.0>

Also note, that the point here is not to optimize _weak_ref_set() (which
is not a hot path). There is work in progress that will use
g_datalist_id_update_atomic() for more purposes (and during more
relevant code paths of GObject).
2025-02-24 17:41:18 +01:00
Yuri Chornoivan
c61a489bcc Update Ukrainian translation 2025-02-24 14:14:22 +00:00
Philip Withnall
7436b8056d Merge branch 'main' into 'main'
doc: Simplify instructions for testing with Automake

See merge request GNOME/glib!4510
2025-02-23 21:55:43 +00:00
Philip Withnall
2910f4b31a Merge branch 'cs-update' into 'main'
Update Czech translation

See merge request GNOME/glib!4512
2025-02-23 21:49:46 +00:00
AsciiWolf
3850646ed2 Update Czech translation 2025-02-23 17:38:26 +01:00
NorwayFun
e2463a846f Update Georgian translation 2025-02-23 06:39:18 +00:00
Philip Withnall
97bd09a04f Merge branch 'wip/smcv/girxml-search-path' into 'main'
tests: Search the appropriate directories for our GIR XML inputs

See merge request GNOME/glib!4509
2025-02-22 14:42:36 +00:00
Reuben Thomas
7804f13d26 doc: Simplify instructions for testing with Automake
This documentation used to link to GLib’s TAP harness. However, the built-in
Automake support works fine, and is simpler to use. Hence, remove most of
the old documentation, and refer users to the Automake manual, adding just
one hint for use with GLib.
2025-02-22 14:34:34 +02:00
Simon McVittie
2c358ec7f8 build: Factor out a variable for the GIR XML directory suffix
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-21 20:12:48 +00:00
Simon McVittie
9f18bb6258 tests: Search the appropriate directories for our GIR XML inputs
During "as-installed" testing, we should search the GIR_DIR for GIR XML,
instead of hard-coding that it is `${prefix}/share/gir-1.0`. This is
not the case on at least Debian, in order to make it possible to
install more than one architecture's flavour of `GLib-2.0.gir`,
which contains some architecture-specific `#define`s.

Also search GOBJECT_INTROSPECTION_DATADIR/GIR_SUFFIX (in practice
something like `/usr/share/gir-1.0` in all cases) to accommodate
distributions like Debian that move the architecture-independent
majority of GIR XML into /usr/share to avoid duplication, leaving
only the architecture-specific minority of files like `GLib-2.0.gir`
in the GIR_DIR.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-21 16:40:47 +00:00
Simon McVittie
135850a534 tests: Reformat gi-compile-repository.py according to black(1)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-21 16:05:43 +00:00
Philip Withnall
05c7f11306 Merge branch 'th/datalist-update-atomic-no-keyid' into 'main'
[th/datalist-update-atomic-no-keyid] gdataset: drop "key_id" argument from GDataListUpdateAtomicFunc

See merge request GNOME/glib!4508
2025-02-21 15:30:25 +00:00
Thomas Haller
6ce489bf83 gdataset: drop "key_id" argument from GDataListUpdateAtomicFunc
None of the users actually care about this parameter. And it's unlikely
that they ever will. Also, the passed "key_id" is the argument from
g_datalist_id_update_atomic(). If the caller really cared to know the
"key_id" in the callback, they could pass it as additional user data.
2025-02-21 15:24:51 +01:00
Philip Withnall
b4224a5d6d Merge branch 'th/gdataset-misc' into 'main'
[th/gdataset-misc] minor improvements in gdataset.c (around g_datalist_id_remove_multiple())

See merge request GNOME/glib!4507
2025-02-21 12:47:57 +00:00
Thomas Haller
70623887ad gdataset: avoid initializing "out_idx" if datalist_find() fails
In some sense, it might be desirable to always initialize out parameters
to something.

However, this fallback index G_MAXUINT32 is not really useful for any
caller. That is, no caller can blindly access the index without checking
whether datalist_find() found (and returned) an entry.

Also, a caller cannot check for whether a entry was found via `if (idx
== G_MAXUINT32)`, because that theoretically is also a valid index.

The only sensible way to use datalist_find() is by accessing "idx"
if-and-only-if an entry was found. And all callers did that.

There is no point for initializing the value.

Uninitialized values can be even preferable over a non-useful
initialization to G_MAXUINT32, because if there is a buggy access them
under valgrind, there will be at least a warning.
2025-02-21 11:09:29 +01:00
Thomas Haller
3024d9b47e gdataset: remove/inline internal function g_data_remove_internal()
This internal function only had one caller. Drop it.
2025-02-21 11:09:29 +01:00
Thomas Haller
82977db352 gdataset/trivial: adjust obsolte code comment
The code comment was no longer correct. g_data_remove_internal() does
not depend on this anymore. It also just calls datalist_find(), which
searches the entire list.
2025-02-21 10:00:45 +01:00
Thomas Haller
76d77d1cab gdataset: avoid initializing temporary array with NULL in g_data_remove_internal()
The code comment was correct in the past, and how the code was then we
had to ensure the array is initialized.

This is no longer the case. We will only access the array at the indexes
from zero to up to (found_keys-1). And those places get always
initialized before we use them (as we increment found_keys at the same
time).

There is no longer a need to initialize this array to zero. Drop this.

Fixes: 3437414dd4f7 ('gdataset: use lookup index in g_datalist_id_remove_multiple()')
2025-02-21 09:55:26 +01:00
Philip Withnall
e35c796e62
2.83.4
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2.83.4
2025-02-20 12:37:13 +00:00
Philip Withnall
c753d26b84 Merge branch 'wip/smcv/gdbus-clear-signal' into 'main'
gdbus: Add g_clear_dbus_signal_subscription() inline convenience function

See merge request GNOME/glib!4493
2025-02-20 00:48:33 +00:00
Simon McVittie
030fbca6c2 gdbus: Add g_clear_dbus_signal_subscription() inline convenience function
This is like g_clear_signal_handler(), but for GDBus signal subscriptions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-20 00:10:02 +00:00
Philip Withnall
0b08232416 Merge branch 'mcatanzaro/mr4206-followup' into 'main'
gcancellable: remove sketchy source ref/unref

See merge request GNOME/glib!4477
2025-02-19 23:32:27 +00:00
Philip Withnall
3a4beabc29 Merge branch 'wip/3v1n0/gmain-more-atomic' into 'main'
gmain: Use atomic logic to handle internal GSource flags

See merge request GNOME/glib!4488
2025-02-19 23:27:51 +00:00
Marco Trevisan (Treviño)
14da9d459c gio/tests/cancellable: Actually init atomic values with atomic functions
This is to make thread sanitizer happy, even those aren't really issues.
2025-02-19 19:38:12 +01:00
Marco Trevisan (Treviño)
ee836d7723 gmain: Use atomic logic to init the ref counting
Ensure we're consistent with the field usage
2025-02-19 19:38:12 +01:00
Marco Trevisan (Treviño)
42283ffb45 gmain: Use atomic logic to set and use dispose function
It can be read/written in a racy way, so let's be safer.
2025-02-19 19:38:12 +01:00
Marco Trevisan (Treviño)
a5bc497021 gmain: Use atomic logic to handle internal GSource flags
We use flags in both locked paths and in public ones (to check if a
source is destroyed or running), but those checks are not using atomic
logic, thus they lead to races in various tests.

Fix them by atomically change and read the values.
And this fixes various tests in thread sanitizer.
2025-02-19 19:36:21 +01:00
Marco Trevisan
30fbe0e859 Merge branch 'wip/3v1n0/gmain-source-reffing-fixes' into 'main'
glib/gmain: Avoid potential dispose race on GSource due to refcount dance

Closes #3612

See merge request GNOME/glib!4501
2025-02-19 18:26:19 +00:00
Marco Trevisan (Treviño)
7097359597 gmain: Ensure old reference is valid during unref
We were checking this already, leading to an extra atomic read that
isn't needed.
2025-02-19 19:03:29 +01:00
Marco Trevisan (Treviño)
5d117b021a gmain: Avoid unneeded atomic read on GSource ref
In g_source_ref() we can just ensure that the value we've referenced was
valid, instead of checking it before, since if get to such state the
GSource is broken anyways, but at least we can avoid doing an unneeded
atomic read.

Reason why we don't bother resetting the reference in case of failure.
2025-02-19 19:03:29 +01:00
Marco Trevisan (Treviño)
6052374c78 gmain: Go back to using the standard unref logic if the final unref failed
If going from 1 -> 0 references failed, then we should restart the unref
process, by potentially re-entering in the dispose function again if
instead something else re-references us and we're going to drop the last
one again.
2025-02-19 19:03:29 +01:00
Marco Trevisan (Treviño)
7b61cc8277 glib/gmain: Avoid potential dispose race on GSource due to refcount dance
During g_source_unref() we might end up calling dispose from
multiple threads, and due to the ref/unref dance we were doing we could
end up initiating a GSource finalization while another thread was about
to revive the source.

This was because we were unreffing a source in a thread, and potentially
re-reffing it, at the same time, but it was not guaranteed that the
final decrement and test couldn't be followed by a further re-ref.

To avoid this, do not do any ref/unref/re-ref/re-unref dance while we're
about to dispose, but instead follow a bit more the g_object_unref()
logic, and start the disposal phase only if we're about to drop the last
reference, and only after the potential disposal call is done, we do an
actual ref count decrement, which may lead to the finalization or not.

We don't bother following the same logic at later point, since after
disposal we should really have just one thread running and revival of a
finalizing GSource isn't supported anyways.

With this logic we can also avoid doing unneeded context locking when
we've enough references on a GSource that disposal is unlikely to
happen.

Closes: #3612
2025-02-19 18:59:33 +01:00
Philip Withnall
01289dd242 Merge branch 'gwin32-com-free-cpp-fix' into 'main'
gwin32.h: Avoid including unknwn.h

Closes #3613

See merge request GNOME/glib!4502
2025-02-19 13:22:03 +00:00
Chun-wei Fan
d920a86e25 gwin32.h: Avoid including unknwn.h
It pulls in windows.h causing conflict for code that assume windows.h is not
previously included.

Thanks to Luca Bacci for proposing this fix, and @Osyotr for pointing
out this issue!

Fixes issue #3613.
2025-02-19 20:52:01 +08:00
Philip Withnall
67a2f8c593 Merge branch '3560-register-object-with-closures' into 'main'
gdbusconnection: Add g_dbus_connection_register_object_with_closures2() API

Closes #3560

See merge request GNOME/glib!4431
2025-02-18 18:45:03 +00:00
Marco Trevisan
c8a81f1b8e Merge branch 'date-time-iso8601-overflow' into 'main'
gdatetime: Fix integer overflow when parsing very long ISO8601 inputs

See merge request GNOME/glib!4498
2025-02-18 18:44:56 +00:00