Commit Graph

25614 Commits

Author SHA1 Message Date
Philip Withnall
7a1a9259a1 gmessages: Clear address before passing it to getpeername()
This will probably make no functional difference, but will squash a
warning from scan-build:
```
../../../../source/glib/glib/gmessages.c:2243:42: warning: The left operand of '==' is a garbage value [core.UndefinedBinaryOperatorResult]
  if (err == 0 && addr.storage.ss_family == AF_UNIX)
                  ~~~~~~~~~~~~~~~~~~~~~~ ^
```

It seems like a reasonable thing to warn about. Initialising the full
union to zero should avoid any possibility of undefined behaviour like
that.

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

Helps: #1767
2022-04-28 10:36:37 +01:00
Emmanuel Fleury
fe2619079f Expand ghook unit tests for a better coverage and better control 2022-04-28 10:35:36 +02:00
Sebastian Dröge
0c1b7b263e Merge branch 'multicast-memcpy-size' into 'main'
gsocket: Add assertions about socket address sizes for memcpy()

See merge request GNOME/glib!2625
2022-04-27 14:32:16 +00:00
Sebastian Dröge
4a1ffd1c79 Merge branch 'gio-tool-set-leak' into 'main'
gio-tool: Fix a minor memory leak when using gio-set with bytestrings

See merge request GNOME/glib!2626
2022-04-27 14:32:13 +00:00
Philip Withnall
49cc9b96f4 gio-tool: Fix a minor memory leak when using gio-set with bytestrings
Tested using:
```sh
touch ~/foo
gio set ~/foo -t bytestring user::test "\x00\x00"
```
(it doesn’t matter that this fails; the bytestring is still decoded)

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

Coverity CID: #1474407
2022-04-27 15:01:08 +01:00
Philip Withnall
ff944776fe gsocket: Add assertions about socket address sizes for memcpy()
These `memcpy()` calls only happen if `g_inet_address_get_family(group)
== G_SOCKET_FAMILY_IPV4`, so the assertions should never fail.

It’s helpful for understanding the code, and for static analysis, to add
the assertions though.

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

Coverity CID: #1486858
2022-04-27 14:47:35 +01:00
Philip Withnall
1dfea6bc93 Merge branch 'timeloop_test' into 'main'
Remove tests/timeloop.c and tests/timeloopbasic.c

See merge request GNOME/glib!2609
2022-04-27 11:47:30 +00:00
Emmanuel Fleury
fd8424a974 Removing unused tests/timeloop.c and tests/timeloop-basic.c
Remove unused tests/timelooop.c and tests/timeloop-basic.c because
these programs are manual performance tests which are no more relevant
for glib. They were used for the writing of GMainLoop but since then
they haven't not much been used in 22 years, it is safe to remove them.

Helps issue #1434
2022-04-26 20:20:03 +02:00
Philip Withnall
eec65c761b gthread: Fix futex timespec type on 32-bit kernels with 64-bit userspace
The `struct timespec` type documented as being passed to the `futex()`
syscall actually needs to be the *kernel’s* timespec type. This will be
a different width from the userspace timespec type if running a 64-bit
userspace on a 32-bit kernel.

That mismatch will cause `g_cond_wait_until()` to return `FALSE`
immediately.

No other uses of `futex()` in GLib use the timeout argument, so they’re
all OK.

Following a detailed suggestion by Rich Felker, pass a different
timespec type into `futex()` if `__NR_futex_time64` is defined. That’s
the 64-bit time version of `futex()` which was added in kernel 5.1, and
which was only added for 32-bit kernels.

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

Fixes: #2634
2022-04-26 13:15:07 +01:00
Philip Withnall
606bdcdb18 Merge branch 'main' into 'main'
Fix the annotation of g_utf8_strncpy()

See merge request GNOME/glib!2621
2022-04-26 10:23:27 +00:00
Hodong
797bcf3224 Fix the annotation of g_utf8_strncpy() 2022-04-26 18:54:57 +09:00
Sebastian Dröge
fa55f37a88 Merge branch 'log-writer-checks' into 'main'
gmessages: Error if g_log_set_writer_func() is called multiple times

See merge request GNOME/glib!2617
2022-04-26 07:41:56 +00:00
Philip Withnall
862e250eaa Merge branch 'fixes_in_tests' into 'main'
Fixes in tests

See merge request GNOME/glib!2608
2022-04-25 17:30:54 +00:00
Philip Withnall
b56f10c890 Revert "glib/gstdio: simplify GStatBuf macro condition for win64"
This reverts commit ae1cccaa0a.

It broke ABI on 64-bit builds with MSVC, as discussed here:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2449#note_1430571.

Fixes: #2633
2022-04-25 17:58:04 +01:00
Philip Withnall
8a498fa989 gversion: Clarify that GLIB_CHECK_VERSION is a >= check
The documentation body makes it sound like it might be a `==` check;
only the ‘returns’ line previously clarified this.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-25 15:20:16 +01:00
Philip Withnall
6dc7b100f5 Merge branch 'gbookmarkfile_tests' into 'main'
Expand tests on gbookmark file API

See merge request GNOME/glib!2610
2022-04-25 13:37:43 +00:00
Philip Withnall
dfb3517d37 gmessages: Error if g_log_set_writer_func() is called multiple times
Inspired by https://gitlab.gnome.org/GNOME/glib/-/issues/2638.

This requires moving the tests to subprocesses, so that
`g_log_set_writer_func()` is only called once per process.

It also adds a test for the new error.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-25 12:38:59 +01:00
Philip Withnall
a44a0c07bd Merge branch 'gtype-boxed-type-macro' into 'main'
docs: Expand G_DEFINE_BOXED_TYPE docs with more detailed example

See merge request GNOME/glib!2612
2022-04-25 10:39:27 +00:00
Logan Rathbone
3a4f0746f5 docs: Expand G_DEFINE_BOXED_TYPE docs with more detailed example 2022-04-25 10:39:27 +00:00
Philip Withnall
cc99d6ee97 Merge branch 'gio-windows' into 'main'
Meson: Fix gio-windows-2.0 override name

See merge request GNOME/glib!2615
2022-04-25 10:30:11 +00:00
Philip Withnall
231a4bb9cb Merge branch 'update-inout-annotations' into 'main'
Add inout annotations for g_iconv

See merge request GNOME/glib!2614
2022-04-25 10:28:39 +00:00
Philip Withnall
7ab50b9e29 Merge branch 'gtestutils-add-stdlib' into 'main'
gtestutils: Include stdlib.h for exit function

See merge request GNOME/glib!2613
2022-04-25 10:27:15 +00:00
Xavier Claessens
199ff2a841 Meson: Fix gio-windows-2.0 override name
The override name must match the pkgconfig name.
2022-04-24 21:29:26 -04:00
TestingPlant
39378b2581 Add inout annotations for g_iconv 2022-04-24 19:15:53 +00:00
Bruce Cowan
444fc6ccda Update British English translation
(cherry picked from commit 82feda1ccf)
2022-04-24 10:31:01 +00:00
Biswapriyo Nath
3c841f18c1 gtestutils: Include stdlib.h for exit function
This fixes warning: implicit declaration of function 'exit'
2022-04-23 14:02:10 +05:30
Milo Ivir
497aba96f1 Update Croatian translation 2022-04-20 17:46:52 +00:00
Emmanuel Fleury
6eddfefbfc Expand tests on gbookmark file API 2022-04-19 16:38:41 +02:00
Ask Hjorth Larsen
d147c36bc6 Updated Danish translation 2022-04-18 19:25:00 +02:00
Emmanuel Fleury
b5c162635c Fix spelling mistake in filename when unlinking it after the test. 2022-04-17 08:08:30 +02:00
Emmanuel Fleury
9ed0dc5583 Clean the file "iochannel-test-outfile" after the test test_small_writes() 2022-04-17 08:08:30 +02:00
Emmanuel Fleury
8901898da2 Cleaning file 'filename' after the test in glib/tests/fileutils.c 2022-04-17 08:08:23 +02:00
Enrico Nicoletto
15d6558ea2 Update Brazilian Portuguese translation 2022-04-15 17:07:22 +00:00
Philip Withnall
41fcb33034 tests: Fix a minor leak in the unicode-normalize test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1487904
2022-04-14 13:26:25 +01:00
Philip Withnall
d987146fe1 Merge branch 'w32-tests' into 'main'
Fix test suite on Windows

See merge request GNOME/glib!2449
2022-04-14 12:16:19 +00:00
Marc-André Lureau
e9f46d3529 gio/tests: fix socket /socket/credentials/unix_socketpair on win32
When I enabled unix socketpair test on win32, I left the existing
g_close(fds[1]), but _g_win32_socketpair() returns native sockets
descriptors that must be closed with closesocket() on win32.

Let GSocket handle the socket pair cleanup.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-04-14 15:38:47 +04:00
Marc-André Lureau
89539d9ae0 gio/tests: GStatBuf.st_size is 64 bits on win64
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-04-14 15:38:47 +04:00
Marc-André Lureau
ae1cccaa0a glib/gstdio: simplify GStatBuf macro condition for win64
As noted by Charlie Barto: "both mingw64 and msvc define _WIN64 in
64-bit mode, and both are LLP64, and both have struct _stat64 defined
the same way."

https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2449#note_1372190

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-04-14 15:38:47 +04:00
Marc-André Lureau
f82f4776c0 tests: fix protocol test on win32
The pipe must be closed, or the child PID watch doesn't get triggered.

We should remove the message callback source on EOF, as EOF during main
loop run will reach a bad assert in the callback.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-04-14 15:38:47 +04:00
Philip Withnall
a072c84d95 Merge branch 'gdate-no-dst' into 'main'
GDate: Fix tests on Windows on certain locales

See merge request GNOME/glib!2600
2022-04-13 21:12:46 +00:00
Chun-wei Fan
a8f1058d3b glib/tests/date.c: Fix 2-digit year test
...for certain Windows locales, since the formats accepted for
g_date_set_parse() will vary depending on the current system locale.  For
instance, g_date_set_parse(gdate, "dd/mm/yy") is accepted on locales such
as zh-HK (Chinese (Hong Kong SAR)) but is rejected on zh-TW (Chinese
(Taiwan)).

One can tell from the "date format" settings in the Windows system
control panel whether there is a "dd/MM/YYYY" or "dd/MM/YY" option from the
drop-down list of date formats to display for the locale, which will indicate
whether g_date_set_parse(gdate, "dd/mm/yy") is accepted, which is true for
zh-HK but is not true for zh-TW.

If g_date_set_parse(gdate, "dd/mm/yy") is not accepted, try again with
g_date_set_parse(gdate, "yy/mm/dd") thereafter for the 2-digit-year tests.
2022-04-13 00:02:57 +08:00
Chun-wei Fan
697d3112b0 gdate.c: Use standard name if no daylight saving exists
We should normally have a standard name for the time zone even if we don't
have daylight saving in the time zone, so use the standard name also when
GetTimeZoneInformation() returns TIME_ZONE_ID_UNKNOWN[1][2].

[1]: https://docs.microsoft.com/en-us/windows/win32/api/timezoneapi/nf-timezoneapi-gettimezoneinformation
[2]: https://docs.microsoft.com/zh-tw/windows/win32/api/timezoneapi/nf-timezoneapi-settimezoneinformation
2022-04-12 23:43:16 +08:00
Philip Withnall
58f54e8303 tests: Reduce wakeup interval in gdbus-threading
When checking that the connection has the expected number of refs, the
test would block on a `GMainContext` iteration for up to 3s before
waking up and failing (if the refcount was still not as expected).

This check was written in the expectation that changing the refcount of
the connection would only happen due to dispatching a source on
`GMainContext` — hence the `GMainContext` would wake up as the refcount
changed.

That’s probably not actually true though. It might be the case that the
connection’s refcount is changed on from the GDBus worker thread, which
would not cause any wakeups on the main thread’s `GMainContext`.

In this case, the `GMainContext` iteration in
`assert_connection_has_one_ref()` would block for the full 3s, and then
wake up and notice the refcount is correct (then the test would
proceed).

That’s fine, apart from the fact that `test_threaded_singleton()` does
this 1000 times. If the slow case is hit on a significant number of
those test runs, the test will take around 3000s to complete, which is
significantly more than meson’s test timeout of 360s. So the test fails
with something like:
```
220/266 glib:gio+slow / gdbus-threading         TIMEOUT 360.07 s

--- command ---
G_TEST_SRCDIR='/builds/GNOME/glib/gio/tests' GIO_MODULE_DIR='' G_TEST_BUILDDIR='/builds/GNOME/glib/_build/gio/tests' /builds/GNOME/glib/_build/gio/tests/gdbus-threading
--- stdout ---
\# random seed: R02S83fe8de22db4d4f376e6d179e2bdd601
1..3
\# Start of gdbus tests
ok 1 /gdbus/delivery-in-thread
ok 2 /gdbus/method-calls-in-thread
\# GLib-GIO-DEBUG: refcount of 0x5602de913660 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913660 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913c60 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913c60 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913260 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913260 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
```

From this log, it can be seen that the sleep is happening on a different
`GMainContext` every other time, so the test *is* making progress.

Assuming this is a correct diagnosis (it’s a lot of guessing), this
commit tries to fix the test by adding a wakeup timeout to the
`GMainContext` in `assert_connection_has_one_ref()`, which will wake it
up every 50ms to re-check the exit condition.

This polling approach has been taken because it doesn’t seem feasible to
make sure that every `g_object_ref()`/`g_object_unref()` call on a
`GDBusConnection` causes the main context to wake up.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 14:39:43 +01:00
Philip Withnall
77416fc023 tests: Use g_assert_*() rather than g_assert() in gdbus-peer-object-manager
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 13:29:19 +01:00
Philip Withnall
20c3ab9e51 tests: Use G_TEST_OPTION_ISOLATE_DIRS in gdbus-peer-object-manager
This might fix a recent test failure:
https://gitlab.gnome.org/GNOME/glib/-/jobs/1929015. Unfortunately
there’s not much debug information in the logs to go on, and I can’t
reproduce it locally. All I have is:
```
192/272 glib:gio / gdbus-peer-object-manager    FAIL     0.43 s (killed by signal 11 SIGSEGV)

--- command ---
GIO_MODULE_DIR='' G_TEST_BUILDDIR='/builds/GNOME/glib/_build/gio/tests' G_TEST_SRCDIR='/builds/GNOME/glib/gio/tests' /builds/GNOME/glib/_build/gio/tests/gdbus-peer-object-manager
--- stdout ---
\# random seed: R02Seee9b7325ecd7c19249a3412397aed9b
1..2
\# Start of gdbus tests
\# Start of peer-object-manager tests
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 13:29:19 +01:00
Philip Withnall
df80a224d7 tests: Use g_test_message() rather than fprintf()
This ensures that the output is redirected properly, and prefixed with
`#` when outputting in TAP mode, so that it doesn’t confuse the TAP
format parser.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 13:21:29 +01:00
Philip Withnall
ba9620f947 tests: Ensure NormalizationTest.txt is installed for installed-tests
This should fix the installed-tests CI failure:
https://gitlab.gnome.org/GNOME/glib/-/jobs/1946794

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-04-12 13:20:48 +01:00
Philip Withnall
fd79c8742b Merge branch 'onceinit_test' into 'main'
Move tests/onceinit.c to glib/tests/onceinit.c

See merge request GNOME/glib!2601
2022-04-12 12:00:27 +00:00
Simon McVittie
bb04fdc013 Merge branch 'wip/pwithnall/fix-bsd-spawn-test' into 'main'
tests: Make a string comparison on an error string more relaxed

See merge request GNOME/glib!2597
2022-04-11 15:16:20 +00:00
Emmanuel Fleury
49ecdd1dba Move tests/onceinit.c to glib/tests/onceinit.c
Related to issue #1434
2022-04-11 15:26:40 +02:00