8781 Commits

Author SHA1 Message Date
Marco Trevisan
82da45c465 Merge branch 'string-test-leak' into 'main'
tests: Fix a minor leak in the GString tests

See merge request GNOME/glib!3207
2023-01-17 21:55:20 +00:00
Marco Trevisan (Treviño)
b3fd737eaa gmessages: Share the same logic to pick the output for log level
Use the very same logic in both the fallback handler and the default handler
2023-01-17 21:10:47 +01:00
Xavier Claessens
19c7d4f15e tests: Use g_test_message() in gdatetime tests 2023-01-17 21:08:49 +01:00
Xavier Claessens
c00135ec73 gtestutils: Do not use default log handler when using TAP
Only use g_test_log() because it will prepend `#` to log messages when
using TAP protocol. Meson >=1.0 rightfully prints a warning when using
TAP protocol and stdout contains non-comment unknown TAP command.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
f893df4b7d gtestutils: Use TAP 13 comments syntax for subtests
Sadly meson 60 doesn't support parsing TAP 14 subtests properly, so it would
fail.

So temporary go back to the previous logic in a simple way so that this
commit can be reverted quickly when we can use a newer meson version.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
28b73434be gtestutils: Use TAP version 14 Subtests syntax to show subtests output
Instead of just commenting all the output of sub-processes we can just use
the TAP 14 syntax for subtests, by using 4-spaces to indent the subtests
output.

This may not work perfectly when there are sub-process that may write
output mixed with the parent, but it should be enough to expose the
hierarchy.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
9cfae23915 gtestutils: Do not allow newlines in Bail out! messages
It would break TAP parsing, so let's just print all inline
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
a3f26bd509 testing: Add TAP test for Bail out! messages 2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
07ff0f7460 gtestutils: Print commented TAP output if running a subprocess
If a gtest process is run as a child of another process, we should not print
the TAP output in plain mode or we'll break the parent results.

We can instead just comment their output so that it gets ignored by TAP
parsers.
2023-01-17 21:08:49 +01:00
Xavier Claessens
28299eb467 gtestutils: "Bail out!" TAP message cannot be multiline
Extra lines must be prepended with `#` which g_test_message() does for
us. Note that lines after "Bail out" are ignored, so we print
stdout/stderr before.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
250f3f0644 gtestutils: Write g_test_message() output in a single operation
Do not write it in multiple lines, to ensure it's going to be written
all together, and nothing else could be written in the middle.

Also optimize a bit the code.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
78a206f467 tests/testing, testing-helper: Add test to check g_test_message on TAP
Ensure that g_test_message() output is conformant to TAP specifications.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
f68c49102e gtestutils: Write log to stderr atomically
We used to send the test log to stderr in pieces, but this could be
problematic when running multiple tests in parallel, so let's just prepare
the string in pieces and write it all at once.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
a943d42104 gtestutils: Use TAP format for all the verbose output
In some cases if verbose output was enabled we were using wrong output
format in TAP mode, so let's fix these cases and run the 'testing' test
case in --verbose mode to ensure we won't regress.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
5c799ff01d gtestutils: Write tap test results atomically
When running multiple tests in parallel using meson, the output could be
mixed and if we write the TAP reports in multiple steps the output could
be mangled together with other results.

An example is: https://gitlab.gnome.org/3v1n0/glib/-/jobs/2507620

Where we have:
  ok 5 /cancellable/poll-fd# GLib-GIO-DEBUG: Collecting capable appnames: 0ms
  # Allocating hashtables:...... 0ms
  # Reading capable apps:        63ms
  # Reading URL associations:... 0ms
  # Reading extension assocs:    78ms
  # Reading exe-only apps:...... 47ms
  # Reading classes:             312ms
  # Reading UWP apps:            47ms
  # Postprocessing:..............16ms
  # TOTAL:                       563ms
   # SKIP Platform not supported

Leading to a clear TAP parsing error
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
254c71e7c6 gtestutils: Set the TAP version 13 as first line of tests output
This is not required, but meson may warn about in future versions, so it's
safer to define it.

However, we must be sure that we only expose it once and in the root binary
if a test file launches another subprocess test file.
To avoid this, we set an environment variable at test init, so that it can
be inherited by children.
It's not the best solution, but for sure the best-effort one without having
to change gtest arguments and called binaries.

Non mentioning a version was considered as assuming we were using TAP
version 12, while no version earlier than 13 can be specified
explicitly so let's use it.

See: https://testanything.org/tap-specification.html
And: https://testanything.org/tap-version-13-specification.html
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
6efbc7c624 meson: Add 'core' suite to glib (only) tests
As per meson default, the project name is a suite per se that is always
added to a test, so running `meson test --suite=glib` is the same as not
passing the `--suite` argument at all, and so making all the tests to run.

To be able to only run the *glib* tests without using the `--no-suite` args,
add a `core` suite that only targets the glib folder tests.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
58031feb17 meson: Use 'tap' test protocol by default
Meson supports tap protocol results parsing, allowing us to track better
the tests that are running (and the ones that are actually skipped) without
manually parsing the test output.

However this also implies that using the verbose mode for a test doesn't
show its output by default (unless there are failures).
2023-01-17 21:08:48 +01:00
Marco Trevisan
f21772ead0 Merge branch 'spawn-test-debugging' into 'main'
tests: Add a test print to spawn-test on Windows

See merge request GNOME/glib!3206
2023-01-17 20:07:25 +00:00
Sebastian Dröge
4d2e77a554 GThreadPool: Always use the thread-spawning thread for the global shared thread pool
Setting the main thread's scheduler settings is not reliably possible,
especially not if SELinux or similar mechanisms are used to limit what
can be done.

As such, get rid of all the complicated code that tried to do this
better and use a separate thread for spawning threads for the global
shared thread pool. These will always inherit the priority of the main
thread (or rather the thread that created the first shared thread pool).

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2769
2023-01-17 19:04:56 +02:00
Marco Trevisan (Treviño)
71a7603e7f gmessages: Avoid strings duplication if there's nothing to format
g_print(), g_printerr() and all the g_log() functions used to always
duplicating a string when printing even if there's nothing to format.

This can be avoided in many cases though, so if a string has no formatting
directive, we can just write it as it is without duplicating and free'ing
it.

From my tests the potential `strchr` overhead is minimal.
2023-01-17 16:41:54 +01:00
Philip Withnall
91d4100a41 tests: Fix a minor leak in the GString tests
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-17 15:34:10 +00:00
Philip Withnall
42b8929407 tests: Add a test print to spawn-test on Windows
To try and debug why the following assert sometimes fails on
`msys2-clang64`, such as in this job:
https://gitlab.gnome.org/GNOME/glib/-/jobs/2515166.

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

Helps: #1371
2023-01-17 15:31:03 +00:00
Philip Withnall
f7a02efbb7 Merge branch 'issue_2883b' into 'main'
Use 'write' with 'count' <= max value of its return type

Closes #2883

See merge request GNOME/glib!3200
2023-01-16 13:08:43 +00:00
CCode
e9e4d52de8 gfileutils: Use 'write' with 'count' <= max value of its return type
Limit `count` so that `write` can properly report the number of written bytes.

Limits:
 - POSIX: `SSIZE_MAX`
 - Windows: `INT_MAX`

Fixes: #2883
2023-01-16 13:08:42 +00:00
Philip Withnall
26728b4ecc Merge branch 'gstring-optimizations' into 'main'
Some GString optimizations

See merge request GNOME/glib!3199
2023-01-16 12:38:54 +00:00
Matthias Clasen
908bd08dc5 Try to make gtk-doc happy 2023-01-14 12:55:25 -05:00
Matthias Clasen
0a26b1c038 markup: Use g_string_truncate
We don't need a private inline helper
for this anymore.
2023-01-14 10:08:42 -05:00
Matthias Clasen
6bb9fdd9c7 markup: Replace a g_string_insert_len call
This lets us use the optimized inline call.
2023-01-14 09:44:22 -05:00
Matthias Clasen
d102a4d8b2 Improve the g_string_truncate test
Test the inline version too.
2023-01-14 09:44:22 -05:00
Matthias Clasen
c191c99748 string: Add an inline g_string_truncate too
This is another very commonly used
GString function.
2023-01-14 09:44:22 -05:00
Matthias Clasen
84780536a4 Improve the g_string_append test
Test the inline versions too, and test
passing -1 for len.
2023-01-14 09:09:19 -05:00
Matthias Clasen
57de9af06f Improve the g_string_append_c test
We should check the resulting string too.
2023-01-14 09:09:19 -05:00
Matthias Clasen
9810803358 string: Optimize g_string_append(_len)
Add static inline versions of these functions
that boil down to just an memcpy. ag_string_append_len
is used quite a bit in GMarkup and GTK's css parser.
2023-01-14 09:09:19 -05:00
Matthias Clasen
0cc74d5a37 string: Add a G_LIKELY
This is the case we optimize for.
2023-01-14 09:09:15 -05:00
Matthias Clasen
34b7992fd6 string: Split g_string_maybe_expand
Split off g_string_expand, and inline just
the size check.
2023-01-14 00:05:34 -05:00
Marco Trevisan
d839282edb Merge branch 'regex-invalid-memory-access' into 'main'
gregex: Prevent invalid memory access for unmatched subpatterns

Closes #2881

See merge request GNOME/glib!3194
2023-01-12 15:22:57 +00:00
Philip Withnall
e9fc91550f Merge branch 'badcel/revert-update-closure-annotations' into 'main'
Revert "Rename user data parameters to user_data"

Closes #2827

See merge request GNOME/glib!3111
2023-01-11 14:58:31 +00:00
Philip Withnall
fdd2d706b2 gregex: Prevent invalid memory access for unmatched subpatterns
Based on a test by Emmanuel Pacaud.

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

Fixes: #2881
2023-01-11 12:14:04 +00:00
Simon McVittie
1955497993 Merge branch 'wip/smcv/gptrarray-null-term' into 'main'
garray: Update NULL termination after copying array content

Closes #2877

See merge request GNOME/glib!3190
2023-01-10 19:51:57 +00:00
Simon McVittie
71f0b3b5ea Merge branch 'wip/smcv/rlimit-nproc-error' into 'main'
tests: Improve error message if setting max processes to 1 fails

See merge request GNOME/glib!3191
2023-01-10 19:28:07 +00:00
Simon McVittie
d3356bdbe9 Merge branch 'wip/smcv/gptrarray-memcpy-nothing' into 'main'
garray: Avoid calling memcpy with no items

See merge request GNOME/glib!3192
2023-01-10 19:27:31 +00:00
Simon McVittie
952b07101f garray: Avoid calling memcpy with no items
`memcpy(NULL, ., n)` and `memcpy(., NULL, n)` are undefined behaviour,
even if *n* is zero.

When len is 0 here, callers are allowed to pass in null data, and
GPtrArray also does not guarantee to have allocated rarray->pdata yet.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-10 13:40:24 +00:00
Simon McVittie
68b9fd53ec garray: Update NULL termination after copying array content
ptr_array_new(len, ., TRUE) ensures that there are at least len+1
elements in pdata, and that pdata[0] is null, but leaves the rest of
pdata uninitialized. After copying the array data into pdata[1] to
pdata[len-1] inclusive, we still need to make sure pdata[len] is a
null terminator.

Note that if len is 0, then pdata is not guaranteed to be non-null. If
it's null, then we can't add null-termination to it until its size
is updated.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2877
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-10 13:35:22 +00:00
Simon McVittie
f42316cb0b tests: Improve error message if setting max processes to 1 fails
This has historically failed on Debian autobuilders, and as a result we
have had a patch for a long time that turned a failure here into a
g_test_skip(). It's not clear whether this still happens, so I'm now
assessing whether the patch can be dropped; but if the prlimit() call
can fail for whatever reason, it would be useful for the error message
to say what limit we were trying to set.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-10 12:48:32 +00:00
Cédric Bellegarde
cf5d807881 docs: Fix return type in cmpint example 2023-01-10 11:31:25 +00:00
badcel
fc70f2c057
Do not name callback parameters "user_data"
Calling a callback parameter "user_data" implicitly adds the "closure" attribute in the documentation which is wrong for callbacks.
2023-01-09 14:12:16 +01:00
badcel
b24f6ca27d
Revert "Rename all user datas in callbacks to user_data"
This reverts commit 1422e5f81241650c634413911e92d23495692545. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
2023-01-09 13:23:32 +01:00
badcel
19a02d7d14
Revert "Rename user data parameters to user_data"
This reverts commit da7a31a052614edd2cc87518585ff371cbb0f204. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
2023-01-09 13:09:26 +01:00
Emmanuele Bassi
684d9aa0c3 build: Don't overwrite build variables
We cannot use `gvisibility_h` for different visibility header files; you
never know when you're going to refer to the variable again, and
projects might end up needing to retrieve the variable contents—like,
for instance, gobject-introspection using glib as a subproject.
2023-01-08 00:33:14 +00:00