Commit Graph

7386 Commits

Author SHA1 Message Date
Aleksandr Mezin
56be1f8d82 gmacros.h: raise minimum GCC version for attribute __noreturn__
`#define G_GNUC_NORETURN __attribute__((__noreturn__))` was previously under
`#if G_GNUC_CHECK_VERSION(2, 4)`.

But `# define G_NORETURN __attribute__ ((__noreturn__))` was under
`#if G_GNUC_CHECK_VERSION(2, 8) || (0x5110 <= __SUNPRO_C)`.

Take the latter for `g_macro__has_attribute(__noreturn__)` fallback. This will
disable `G_GNUC_NORETURN` for GCC 2.4-2.7 though.
2021-04-16 14:51:41 +06:00
Aleksandr Mezin
2b9bf7b162 gmacros.h: use g_macro__has_attribute() where possible
Fall back to compiler version checks only when `__has_attribute()` is not
available.

clang-cl doesn't define `__GNU__`, but still accepts attributes. This change
gets rid of a lot of warnings when building GLib with clang-cl. For GCC and
non-cl Clang nothing should change.
2021-04-16 14:45:03 +06:00
Emmanuel Fleury
8ad4f752b1 Fix signedness warning in glib/gstring.c
glib/gstring.c: In function ‘g_string_replace’:
glib/gstring.c:998:13: warning: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  998 |       if (n == limit)
      |             ^~
2021-04-14 23:26:15 +02:00
Matthias Clasen
63fa4e7d34 gerror: Clarify docs around message requirements
Make it clear that error->message is a user-visible string
that must be in UTF-8, and point out helpers for that.
2021-04-14 14:55:23 -04:00
Philip Withnall
23277fbcad Merge branch 'wip/clarify-ref-count-api' into 'master'
refcount: Clarify when the ref count ends up undefined

See merge request GNOME/glib!2041
2021-04-13 13:41:19 +00:00
Dor Askayo
eb6ca282f0 grefcount: Clarify that the initial reference count is 1 2021-04-09 13:15:30 +03:00
Jonas Ådahl
21cc809158 refcount: Clarify when the ref count ends up undefined
Calling g_atomic_ref_count_dec() or g_ref_count_dec() and the reference
count reaches zero results in different side effects depending on
whether the reference count is atomic or not.

The intended side effect when this happens is undefined, i.e. one should
not rely on the reference count actually reaching zero, or staying 1, or
becoming something else, and one should treat the grefcount /
gatomicrefcount to be unusable until reinitialized.

This wasn't documented, so add a paragraph about this.
2021-04-09 11:13:36 +02:00
Michael Catanzaro
f97ff20adf Implement G_ANALYZER_NORETURN for Coverity
This change is proposed by Kamil Dudka. It teaches Coverity to assume
that g_critical() will never return, which is desirable for the same
reasons it is for scan-build: once you've triggered undefined behavior,
the game is already lost, and there's limited benefit from trying to
avoid every possible memory leak on such codepaths. Notably, this
affects g_return_if_fail().

Arguably it might be desirable to fix every such issue, but if we're
already not doing so for scan-build, it doesn't make sense to hold
developers working with Coverity to a higher standard. This allows
focusing on more serious issues found by Coverity.

Thanks Kamil!
2021-04-08 11:34:21 -05:00
Philip Withnall
80c2981b62 Merge branch 'fix-glib-unavailable-macro' into 'master'
gmacros.h: Complete the use of GLIB_UNAVAILABLE_MACRO

Closes #2376

See merge request GNOME/glib!2037
2021-04-08 15:52:27 +00:00
Gaël Bonithon
52ad3ed717 gmacros.h: Fix stringification in some macros
This makes `GLIB_UNAVAILABLE_MACRO` and `GLIB_DEPRECATED_MACRO_FOR`
print their arguments correctly.
2021-04-08 17:33:07 +02:00
Gaël Bonithon
f20bcf2969 gmacros.h: Complete the use of GLIB_AVAILABLE_MACRO_IN_*
This adds `GLIB_AVAILABLE_MACRO_IN_*` where needed, or a comment when
such use is not possible.

Fixes #2376.
2021-04-08 17:33:07 +02:00
Emmanuel Fleury
b9e66a59f6 Fix signedness warning in glib/gdate.c
glib/gdate.c: In function ‘convert_twodigit_year’:
glib/gdate.c:1217:13: warning: comparison of integer expressions of
  different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1217 |       if (y < two)
      |             ^
2021-04-08 13:29:05 +02:00
Aleksandr Mezin
2539d70d40 gmacros.h: use G_GNUC_CHECK_VERSION
Remove repeated `__GNUC__ > ... || (__GNUC__ == ... && __GNUC_MINOR__ >= ...)`.

Also effectively adds (missing?) `defined(__GNUC__)` check before
`__GNUC__ > ...` in a few places.
2021-04-07 23:58:51 +06:00
Emmanuele Bassi
85eec6aae8 Split g_test_log() messages that contain multiple lines
When using TAP we want every single line to be one of the following:

 - a valid TAP clause
 - a comment
 - a blank line

Typical explicit test logs are single line comments, but in some cases
we might end up printing debug messages from libraries, and those may
contain multiple lines. When that happens, we break the TAP and fail the
test in conditions entirely outside of our control.

One option to avoid outright failure is to always prepend each line of a
messge with `#`, to ensure that the whole thing is considered a comment.
2021-04-07 16:19:34 +01:00
Philip Withnall
e7f6799668 Merge branch '2055-correct-date-format-utf8' into 'master'
Resolve "g_date_time_format() does not return UTF-8 if LC_TIME is not UTF8 but other locale settings are UTF-8"

Closes #2055

See merge request GNOME/glib!1777
2021-03-31 16:16:16 +00:00
Chun-wei Fan
f801c84c52 gmacros.h: Improve check for C _Static_assert
Use the GCC/Clang macros __has_extension() and __has_feature() on
c_static_assert, which is the documented way for GCC/CLang to check for
_Static_assert if C11 mode is not enabled, as suggested by Aleksandr Mezin.

As a result, add a private macro that is defined to be __has_extension if it
exists, otherwise it is considered to be always false.
2021-03-30 16:45:07 +08:00
Chun-wei Fan
7b76995298 gmacros.h: Use _Static_assert for clang
It appears that CLang supports _Static_assert() even when not in C11
mode, since at least CLang 3.1, so let's just use that for CLang builds.

Fixes issue #2338.
2021-03-30 16:45:07 +08:00
Frederic Martinsons
782eb1f7af Add private functions to correctly convert datetime when LC_TIME is not UTF8
Functions (_g_get_time_charset and _g_get_ctype_charset) to get LC_TIME and LC_CTYPE charset
by using nl_langinfo with _NL_TIME_CODESET and CODESET).
Another functions (_g_locale_time_to_utf8 and _g_locale_ctype_to_utf8) which uses thel and format
the input string accordingly.
Add new test cases with mixing UTF8 and non UTF8 LC_TIME along with UTF8
and non UTF8 LC_MESSAGES.

Closed #2055

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-27 09:28:10 +01:00
Frederic Martinsons
c4df3b23c4 Reorganize headers inclusion alphabetically
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-27 08:29:08 +01:00
Frederic Martinsons
b4f2002919 Correct FIXME by implementing a function for converting two digits year
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-03-27 08:29:08 +01:00
Philip Withnall
b657e78add galloca: Clarify alloca() sizes must always be controlled by the program
To avoid security vulnerabilities.

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

Fixes: #2363
2021-03-25 12:55:21 +00:00
Philip Withnall
55cbc31517 Merge branch 'master' into 'master'
make g_tree_remove_all public

See merge request GNOME/glib!1986
2021-03-24 12:13:18 +00:00
Avinash Sonawane
5ce6ba287f docs: Replace git.gnome.org with gitlab.gnome.org urls 2021-03-24 16:18:53 +05:30
Philip Withnall
34e4841854 gkeyfile: Fix crash when parsing translations on a second load
If the same `GKeyFile` is reused to load multiple different key files,
any loads after the first which encounter translated keys will crash,
because clearing the data from the first load cleared the cached
language names, but didn’t clear `checked_locales`, so they were never
reloaded.

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

Fixes: #2361
2021-03-23 16:33:33 +00:00
Philip Withnall
164da19983 gkeyfile: Drop a redundant check
It should not be possible for `->locales` to be set without
`->checked_locales` being set, so drop the redundant check. This helps
with branch code coverage.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-03-23 16:27:49 +00:00
liuyangming
8fb3101715 gtree: Make g_tree_remove_all() public
g_tree_remove_all is useful and the corresponding function in GHashTable
is exposed, so make this function public is meaningful.
2021-03-23 11:36:57 +00:00
Simon McVittie
6c5a227bcc gmain: Add g_steal_fd() to API
This is basically glnx_steal_fd() from libglnx. We already had two
private implementations of it in GLib.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-22 11:48:10 +00:00
Philip Chimento
748103d75a introspection: Remove 'caller-allocates' from POD types
The (out caller-allocates) and (out callee-allocates) annotations are
meant for structured or pointer types. Plain old data types are just
regular out parameters and don't need the annotation about who
allocates them.

See: https://gitlab.gnome.org/GNOME/gjs/-/issues/386
2021-03-20 11:14:15 -07:00
Avinash Sonawane
b21766ec3c goption.c: Simplfy parse_short_option() 2021-03-19 14:08:27 +05:30
Andy Fiddaman
1fafbb82b0 Include glibconfig.h to get the G_OS_UNIX token 2021-03-18 16:21:42 +00:00
Simon McVittie
1248b642ad gversionmacros: Add version macros for GLib 2.70
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-18 13:58:41 +00:00
Michael Catanzaro
3a74ad128e tests: Fix copy/paste error in queue test
Coverity is pretty good at detecting copy/paste errors.
2021-03-16 12:53:44 -05:00
Philip Withnall
c92d9dc267 enums: Add missing GLIB_AVAILABLE_ENUMERATOR_IN_2_68 annotations
In the 2.68 cycle we’d added 3 new enumerator elements. Due to the
preceding commit, they can now be annotated with
`GLIB_AVAILABLE_ENUMERATOR_IN_2_68`, which will make it a bit easier for
third party projects to notice when they’re using these symbols without
having bumped their GLib dependency.

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

Fixes: #2327
2021-03-11 13:37:49 +00:00
Aleksandr Mezin
d18bdef42d gbitlock.c: replace remaining 'asm' with '__asm__'
Commit 2330f7e65e changed 'asm' to '__asm__' in
g_bit_lock and g_bit_trylock.

Replace 'asm' with '__asm__' in the remaining functions.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2344
2021-03-04 04:39:27 +06:00
Philip Withnall
6cc6df230a Merge branch 'glib-typeof-gatomic-h' into 'master'
gatomic.h: Make `glib_typeof` API break opt in.

See merge request GNOME/glib!1975
2021-03-01 13:19:08 +00:00
Iain Lane
5b3e4f94b0
gatomic.h: Make glib_typeof API break opt in.
The changes in 4273c43902 did not guard
macros in `gatomic.h` which use `glib_typeof`. This meant that when
552b8fd862 was committed, moving the
include of `<type_traits>` under such a guard, these macros were still
trying to use it. This broke the build of at least vte.

Fix this by guarding the API break in `gatomic.h` too.
2021-03-01 09:18:03 +00:00
Olivier Brunel
ddb2b5fe54 GRWLock: Tweak doc to make things a bit clearer
The doc used different phrasing for the same thing, e.g. "if any thread"
vs "any other thread."

Also make it clear that trying to take a write lock while already having
a lock, or trying to take a read lock while having a write lock, is
undefined.
2021-02-27 20:34:30 +01: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
b018730087 tests: Add missing NULL terminator to spawn-singlethread test
This should have been in commit
b31f3f5f80.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 15:08:47 +00:00
Philip Withnall
51e964849b Merge branch '2097-spawn-fd-rewriting' into 'master'
Resolve "GSubprocessLauncher with FD assignment can clash with g_spawn_async internal pipe"

Closes #2097

See merge request GNOME/glib!1690
2021-02-16 14:04:39 +00:00
Philip Withnall
eebb66280d gspawn-win32: Various minor internal const-correctness fixes
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
ea9fd4c2f2 gspawn-win32: Implement g_spawn_async_with_pipes_and_fds()
The `source_fds`/`target_fds` functionality is not supported on Windows
at the moment.

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

Fixes: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
a34b674134 gspawn-win32: Refactor internal spawn functions
This should introduce no functional changes, but condenses the variants
of the internal spawn implementation down to be more like `gspawn.c`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
ba403908a2 gspawn-win32: Rename a variable for consistency with the public headers
I realise Windows uses handles rather than PIDs, but given that there
are multiple platform-specific implementations of the public
`g_spawn_*()` API, I think it is less confusing for them all to use the
same naming scheme.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
fd0b20d537 gspawn: Minor improvements to documentation formatting
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
b31f3f5f80 gspawn: Add new g_spawn_async_with_pipes_and_fds() API
This is a simple wrapper around the new source/target FD mapping
functionality in `fork_exec()`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
52dc7cb9dd tests: Add setlocale() call to spawn-singlethread
This allows non-ASCII characters to be used in test messages from it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
c5f3ba7f01 gspawn: Avoid merged FDs being closed on exec()
If `stdout_fd` was set to (say) 6, and `stderr_fd` was set to 1, the
`set_cloexec()` call for setting up `stderr` would set the new `stdout`
for the forked process to be closed in the pending `exec()`.

This would cause the child process to error when writing to `stdout`.

This situation happens when using `G_SUBPROCESS_FLAGS_STDERR_MERGE`.

Add some conditions to prevent setting `CLOEXEC` in such cases.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
f20f0d385e gspawn: Avoid custom FDs conflicting with the child_err_report_fd
It was previously possible to specify the FD number which
`child_err_report_fd` was assigned, as a target FD in the FD mapping set
up using `g_subprocess_launcher_take_fd()`.

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

Fixes: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
7be9767cc4 gspawn: Handle arbitrary FD passing and renumbering between fork/exec
This effectively moves some of the functionality of `GSubprocess`
(`g_subprocess_launcher_take_fd()`) into `g_spawn*()`, which should make
implementation a little simpler.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
cddcd24b52 gspawn: Combine fork_exec() implementations
This is an internal change which won’t affect the public API. It should
introduce no functional changes, but simplifies the code a little.

The arguments from `fork_exec_with_pipes()` have been added to
`fork_exec_with_fds()`. `child_close_fds` has been dropped since it’s
now an implementation detail within the function.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
58dd7a37c9 Merge branch 'wip/smcv/armel-atomic-pointer-get' into 'master'
gatomic: Make fallback g_atomic_pointer_get type-safe

See merge request GNOME/glib!1949
2021-02-15 21:47:41 +00:00
Philip Withnall
63467c559e gspawn: Remove spurious blank lines
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-15 12:28:56 +00:00
Philip Withnall
12a627be55 gspawn: Reindent some arguments
They were indented incorrectly and I’m about to add some additional
ones.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2021-02-15 12:28:56 +00:00
Philip Withnall
3dec1b2c00 Merge branch '2319-memdup-deprecation' into 'master'
gstrfuncs: Deprecate g_memdup() in favour of g_memdup2()

Closes #2319

See merge request GNOME/glib!1928
2021-02-15 12:19:31 +00:00
Simon McVittie
d2b4ba55cb gatomic: Make fallback g_atomic_pointer_get type-safe
Since !1715, g_atomic_pointer_get (&x) has usually returned the type of
x, rather than a generic pointer, in C++ code (where x is any pointer,
or any pointer-sized integer such as guintptr). glib/tests/cxx.cpp
asserts that this is the case.

However, this was only implemented for the lock-free fast-path, not
for the slow path used in platforms with an ARMv5 baseline (and
therefore no atomic instructions) such as Debian armel.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-14 23:38:35 +00:00
Matthias Clasen
5bad389e63 Add a test for parsing 0 as double
Add a test for #2329.
2021-02-13 14:41:44 -05:00
Krzesimir Nowak
acb7b0ec69 gbytearray: Do not accept too large byte arrays
GByteArray uses guint for storing the length of the byte array, but it
also has a constructor (g_byte_array_new_take) that takes length as a
gsize. gsize may be larger than guint (64 bits for gsize vs 32 bits
for guint). It is possible to call the function with a value greater
than G_MAXUINT, which will result in silent length truncation. This
may happen as a result of unreffing GBytes into GByteArray, so rather
be loud about it.

(Test case tweaked by Philip Withnall.)
2021-02-11 10:14:15 +00:00
Kjell Ahlstedt
e008301cf8 guniprop, glib/tests/unicode: Fix style issues 2021-02-10 18:25:53 +02:00
Kjell Ahlstedt
b9a4897900 guniprop: Fix g_utf8_strdown() for Turkish locale
In the Turkish locale the lowercase equivalent of a capital I with dot above
is a normal lowercase i with a dot above.

Fixes part of issue #390
2021-02-10 18:25:53 +02:00
Joshua Lee
c576a4cd82 string: Add find and replace function
This adds g_string_replace(), a function that replaces instances of one string
with another in a GString. It allows the caller to specify the maximum number
of replacements to perform, and returns the number of replacements performed
to the caller.

Fixes: #225
2021-02-09 10:50:16 +00:00
Simon McVittie
63f37f8c3b io-channel test: Add coverage for g_io_channel_set_line_term(., ., -1)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 10:37:01 +00:00
Simon McVittie
5dc8b0014c giochannel: Don't store negative line_term_len in GIOChannel struct
Adding test coverage indicated that this was another bug in 0cc11f74.

Fixes: 0cc11f74 "giochannel: Forbid very long line terminator strings"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2323
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 10:37:01 +00:00
Jan Alexander Steffens (heftig)
a149bf2f90
giochannel: Fix length_size bounds check
The inverted condition is an obvious error introduced by ecdf91400e.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2323
2021-02-07 23:32:40 +01:00
Philip Withnall
feff097f27 gstrfuncs: Deprecate g_memdup() in favour of g_memdup2()
Unfortunately, `g_memdup()` accepts its size argument as a `guint`,
unlike most other functions which deal with memory sizes — they all use
`gsize`. `gsize` is 64 bits on 64-bit machines, while `guint` is only 32
bits. This can lead to a silent (with default compiler warnings)
truncation of the value provided by the caller. For large values, this
will result in the returned heap allocation being significantly smaller
than the caller expects, which will then lead to buffer overflow
reads/writes.

Any code using `g_memdup()` should immediately port to `g_memdup2()` and
check the pointer arithmetic around their call site to ensure there
aren’t other overflows.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: #2319
2021-02-04 17:34:03 +00:00
Philip Withnall
0cc11f745e giochannel: Forbid very long line terminator strings
The public API `GIOChannel.line_term_len` is only a `guint`. Ensure that
nul-terminated strings passed to `g_io_channel_set_line_term()` can’t
exceed that length. Use `g_memdup2()` to avoid a warning (`g_memdup()`
is due to be deprecated), but not to avoid a bug, since it’s also
limited to `G_MAXUINT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
2021-02-04 16:17:21 +00:00
Philip Withnall
19470722b3 glib: 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()` or an existing `gsize`
variable), 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

In particular, this fixes an overflow within `g_bytes_new()`, identified
as GHSL-2021-045 by GHSL team member Kevin Backhouse.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: GHSL-2021-045
Helps: #2319
2021-02-04 16:04:10 +00:00
Philip Withnall
f8cf0b8672 gstrfuncs: Add g_memdup2() function
This will replace the existing `g_memdup()` function, which has an
unavoidable security flaw of taking its `byte_size` argument as a
`guint` rather than as a `gsize`. Most callers will expect it to be a
`gsize`, and may pass in large values which could silently be truncated,
resulting in an undersize allocation compared to what the caller
expects.

This could lead to a classic buffer overflow vulnerability for many
callers of `g_memdup()`.

`g_memdup2()`, in comparison, takes its `byte_size` as a `gsize`.

Spotted by Kevin Backhouse of GHSL.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: GHSL-2021-045
Helps: #2319
2021-02-04 14:13:03 +00:00
Sebastian Dröge
8385664f47 Merge branch 'master' into 'master'
gdatetime: Add math library support

Closes #2314

See merge request GNOME/glib!1916
2021-02-04 08:03:22 +00:00
Xavier Claessens
580b415ebd atomic: Fix type check of g_atomic_pointer_compare_and_exchange() 2021-02-03 09:37:04 -05:00
Xavier Claessens
7459bf9a19 Revert "atomic: Fix type error with clang++"
This reverts commit d95885d91e.
2021-02-03 09:37:04 -05:00
Philip Withnall
ab46205db1 Merge branch 'carlosgc/uri-host-nullable' into 'master'
guri: Mark g_uri_get_host as nullable

See merge request GNOME/glib!1921
2021-02-03 09:59:29 +00:00
Carlos Garcia Campos
5221b6a261 guri: Mark g_uri_get_host as nullable
It's currently annotated as not nullable, but it can be NULL.
2021-02-03 09:47:30 +00:00
Prasanth R
62fc437773 gdatetime: Add math library support
W.r.to c3805d74b uClibc fails in linking
Fixes #2314
2021-02-03 14:09:10 +05:30
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
Sebastian Dröge
02fbe86e07 Mark g_key_file_get_comment() key parameter as nullable
It will return the comment above the group (or at the top of the file)
then according to the documentation.
2021-02-02 10:14:57 +02:00
Philip Withnall
6cca256526 Merge branch 'wip/avoid-searching-path' into 'master'
spawn: Don't set a search path if we don't want to search PATH

See merge request GNOME/glib!1902
2021-02-01 11:58:51 +00:00
Simon McVittie
f378352051 tests: Mark tests with AddressSanitizer-detected leaks
Various tests have leaks where it isn't clear whether the data is
intentionally not freed, or leaked due to a bug. If we mark these
tests as TODO, we can skip them under AddressSanitizer and get the
rest to pass, giving us a baseline from which to avoid regressions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 11:19:59 +00:00
Simon McVittie
41ed1c6d5d gutils: Tell AddressSanitizer not to track previous XDG directories
We reset these in some unit tests, and must deliberately leak them to
avoid having to break API.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
023793071b glib-private: Add wrappers for telling AddressSanitizer to ignore leaks
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
9fef98cf84 gtestutils: Default to -m no-undefined under AddressSanitizer
AddressSanitizer detects memory leaks, NULL parameters where only a
non-NULL parameter is expected, and other suspicious behaviour, so if
we try to test that sort of thing we can expect it to fail.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
98804781ce glib-private: Add infrastructure to detect AddressSanitizer
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
def3e33c36 error test: Don't test programmer error if asked not to
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00
Simon McVittie
a85c126602 Expand test coverage for G_SPAWN_SEARCH_PATH
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-31 14:15:37 +00:00
Thomas Haller
e864c6577a spawn: prefer allocating buffers on stack for small sizes to avoid valgrind leaks
We preallocate buffers that are used after forked. That is because
malloc()/free() are not async-signal-safe and must not be used between
fork() and exec().

However, for the child process that exits without fork, valgrind wrongly
reports these buffers as leaked.
That can be suppressed with "--child-silent-after-fork=yes", but it is
cumbersome.

Work around by trying to allocate the buffers on the stack. At
least in the common cases where the pointers are small enough
so that we can reasonably do that.

If the buffers happen to be large, we still allocate them on the heap
and the problem still happens. Maybe we could have also allocated them
as thread_local, but currently glib doesn't use that.

[smcv: Cosmetic adjustments to address review comments from pwithnall]
2021-01-31 13:37:13 +00:00
Simon McVittie
82adfd7e3a Add test coverage for G_SPAWN_SEARCH_PATH
For manual test coverage that would reproduce the bug fixed in !1902,
copy /bin/true (or any other harmless executable) to
/usr/bin/spawn-test-helper.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-28 18:37:45 +00:00
Simon McVittie
7ff0fb3af5 spawn: Don't set a search path if we don't want to search PATH
do_exec() and g_execute() rely on being passed a NULL search path
if we intend to avoid searching the PATH, but since the refactoring
in commit 62ce66d4, this was never done. This resulted in some spawn
calls searching the PATH when it was not intended.

Spawn calls that go through the posix_spawn fast-path were unaffected.

The deprecated gtester utility, as used in GTK 3, relies on the
ability to run an executable from the current working directory by
omitting the G_SPAWN_SEARCH_PATH flag. This *mostly* worked, because
our fallback PATH ends with ".". However, if an executable of the
same name existed in /usr/bin or /bin, it would run that instead of the
intended test: in particular, GTK 3's build-time tests failed if
ImageMagick happens to be installed, because gtester would accidentally
run display(1) instead of testsuite/gdk/display.

Fixes: 62ce66d4 "gspawn: Don’t use getenv() in async-signal-safe context"
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=977961
2021-01-28 16:49:06 +00: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
Xavier Claessens
d95885d91e atomic: Fix type error with clang++
clang++ checks the 2nd args of __atomic_compare_exchange_n() has the
same type as the first, which fails when 2nd arg is nullptr which is of
type nullptr_t.

Ideally it should do `glib_typeof (*(atomic)) gapcae_oldval = (oldval);`
to ensure oldval and atomic have compatible types but unfortunately that
does not work neither.

Since that function never has been typesafe, and it is not even
attempting to use glib_typeof in case __ATOMIC_SEQ_CST is not defined,
drop it in __atomic_ case too.

Fixes issue #2226.
2021-01-27 09:23:48 -05:00
Xavier Claessens
51003d409b Use C++11 decltype where possible
There are various places glib uses __typeof__ for type safety, but
that's a GNUC extension. C++11 has standard decltype() that does a
similar job, at least for cases we care about.

This avoids C++ code to always have to cast return value of
g_object_ref() which was causing type kind of error:

error: invalid conversion from ‘gpointer’ {aka ‘void*’} to
‘GstElementFactory*’ {aka ‘_GstElementFactory*’} [-fpermissive]
2021-01-27 09:23:48 -05:00
Jonas Ådahl
657d18fdbb gtestutils: Add g_test_get_path() API
I found myself wanting to know the test that is currently being run,
where e.g. __func__ would be inconvenient to use, because e.g. the place
the string was needed was not in the test case function. Using __func__
also relies on the test function itself containing the whole path, while
loosing the "/" information that is part of the test path.
2021-01-25 16:34:12 +01:00
Philip Withnall
bff359dde6 docs: Add documentation for GLIB_VERSION_CUR_STABLE and PREV_STABLE
It was missing. Oh no!

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-19 15:52:29 +00:00
Seungha Yang
5763ddae3c gthread-win32: Use SetThreadDescription Win32 API for setting thread name
Since Windows 10 1607, we can make use of SetThreadDescription() API
for setting thread name. Unlike previously used exception based
method, this API will preserve configured thread name on dump file.
2021-01-15 01:45:59 +09:00
Philip Withnall
0e6467af5d gutils: Document caching of XDG directory variables
See: #2278.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-14 11:32:57 +00:00
Philip Withnall
d6c670c27e gerror: Minor documentation formatting fixes
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-13 13:29:48 +00:00
Philip Withnall
11097160c0 gerror: Add a heading for the docs section on extended GErrors
This makes it a little easier to link to in the generated documentation,
and separates it from the section above.

Link to the heading from the documentation for
`G_DEFINE_EXTENDED_ERROR`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-13 13:29:02 +00:00
Philip Withnall
b2230cb3d1 gerror: Document in the GError rules that stack allocation is bad
It means that extended error domains can’t be used.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-13 13:28:29 +00:00
Philip Withnall
885d65077e tests: Only run g_error_new_valist() programmer error test on Linux
On FreeBSD it always crashes due to the platform’s `vasprintf()`
implementation being less forgiving than Linux’s. That’s fine.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-07 16:17:28 +00:00
Philip Withnall
5000193cf3 tests: Ignore -Wformat-nonliteral warning in new GError tests
See !1861.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-07 15:47:59 +00:00
Philip Withnall
2cbcb2bda5 tests: Add various tests to bring GError coverage up to 100%
This is mostly to cover historic code, but also includes a couple of
additional tests for extended error domains (see #14).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-06 17:54:30 +00:00
Philip Withnall
e233859544 gerror: Drop a redundant condition
At this point, if `dest` is non-`NULL` then we can guarantee
`*dest != NULL` due to `g_propagate_error()` succeeding.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-06 17:24:00 +00:00
Philip Withnall
7f7512b62e gerror: Drop a redundant branch
At this point, `src` is guaranteed to be non-`NULL` due to the
	precondition check.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-06 17:23:31 +00:00
Philip Withnall
8a5cc02142 Merge branch 'extended-error' into 'master'
Extended error

See merge request GNOME/glib!1304
2021-01-06 16:02:27 +00:00
Krzesimir Nowak
80014804e2 gerror: Inform valgrind about our memory trickery
This is mostly duplicated code from gtype.c.
2021-01-06 15:44:59 +00:00
Krzesimir Nowak
ae72f9de35 gerror: Add support for extended errors
This commit adds a G_DEFINE_EXTENDED_ERROR macro and
g_error_domain_register() functions to register extended error
domains.
2021-01-06 15:44:59 +00:00
Sebastian Dröge
609d1e292f Merge branch 'fix/android-system-checks' into 'master'
build: Fix Android system checks

See merge request GNOME/glib!1856
2021-01-06 08:34:52 +00:00
Sebastian Dröge
179679837b Merge branch 'fix/assert-not-reached-on-msvc' into 'master'
gtestutils: Fix g_assert_not_reached() on MSVC

See merge request GNOME/glib!1857
2021-01-06 08:32:58 +00:00
Sebastian Dröge
1810761d8e Merge branch 'fix/always-use-windows-unicode-apis' into 'master'
gwin32: Always use unicode APIs

See merge request GNOME/glib!1848
2021-01-06 08:26:18 +00:00
Sebastian Dröge
82d3b49438 Merge branch 'feature/clang-native-mutex' into 'master'
gthread: Port native mutex to Clang

See merge request GNOME/glib!1842
2021-01-06 08:11:02 +00:00
Ole André Vadla Ravnås
d35a606852 gtestutils: Fix g_assert_not_reached() on MSVC
When building with G_DISABLE_ASSERT.
2021-01-06 01:17:31 +01:00
Ole André Vadla Ravnås
7b7f987a36 build: Add missing host system checks for Android 2021-01-06 01:06:28 +01:00
Ole André Vadla Ravnås
0ab51f8d4e gwin32: Always use unicode APIs
Instead of the legacy ANSI ones. This also means GLib behaves correctly
when built with unicode preprocessor defines.
2021-01-05 21:42:59 +01:00
Ole André Vadla Ravnås
f1a1e84dda gthread: Port native mutex to Clang
And other toolchains that support stdatomic.
2021-01-05 20:57:04 +01:00
Ole André Vadla Ravnås
d45d9f738c gthread: Fix incorrect cast 2021-01-05 20:44:55 +01:00
Philip Withnall
ea6fe7194a gerror: Clarify reference to g_key_file_has_key() in documentation
It’s not actually deprecated, but it is hard to use. It was briefly
deprecated, but then the deprecation was reversed before a stable
release.

See https://bugzilla.gnome.org/show_bug.cgi?id=650345.

Reported on StackOverflow as
https://stackoverflow.com/q/65505393/2931197.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-04 16:44:12 +00:00
Philip Withnall
bf0430f10e gerror: Improve documentation formatting slightly
No functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-04 16:43:37 +00:00
Philip Withnall
1ae734dd6d Merge branch 'wip/jtojnar/gsrc-dstr-example' into 'master'
Modernize g_source_is_destroyed example

Closes #2279

See merge request GNOME/glib!1835
2021-01-04 16:11:14 +00:00
Jan Tojnar
720dfa8cd3 Modernize g_source_is_destroyed example
gtk_threads_{leave,enter} API is deprecated and a narrower critical section,
guarding just idle_id manipulation, is better anyway.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2279
2021-01-04 15:42:03 +00:00
Chun-wei Fan
a2454d731a gdatetime.c: Fix MSVC builds for lack of NAN items
Use a fallback for isnan() on Visual Studio 2012 or earlier, and define
NAN if it does not exist.
2021-01-04 15:38:27 +00:00
Timm Bäder
89f12e10b6 keyfile: Only allocate group_hash if needed
A keyfile with no groups (e.g. an empty one) does not need a hash table
for the groups.
2020-12-31 14:58:37 +01:00
Timm Bäder
3ee05ef3bd keyfile: Don't allocate parse_buffer if we don't need it
When loading a GKeyFile, the sequence is usually:

keyfile = g_key_file_new();
g_key_file_load_xxx(keyfile, ...)

g_key_file_new() calls g_key_file_init(), which allocates a parse_buffer
for parsing. g_key_file_load_xxx() will then g_key_file_clear() the
keyfile and call g_key_file_init() again.

Just don't allocate a parse_buffer unless we need it for parsing.
2020-12-31 14:58:37 +01:00
Timm Bäder
03ca87586f fileutils: Avoid calling set_file_error with NULL GError**
If no pointer to a GError* has been passed to public API, there's not
need to look at translations via gettext or format an error message that
g_set_error_literal will entirely ignore in the end.
2020-12-31 14:58:37 +01:00
Timm Bäder
037f1ce672 keyfile: Delay calling g_get_language_names() until it's needed
The g_get_languages() call is quite costly and often unneeded.
2020-12-30 12:39:14 +01:00
Krzesimir Nowak
b715e4c9d0 gerror: Simplify error construction
Factor out the GError creation to a common function. When adding a
support for extended error types, this will limit the number of places
where these errors are allocated.
2020-12-23 23:17:41 +01:00
Philip Withnall
fec38762b3 gdate: Use string length when validating UTF-8
Makes the validation a tiny bit faster.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-21 16:50:53 +00:00
Philip Withnall
15634d64bf gdate: Limit length of dates which can be parsed as valid
Realistically any date over 200 bytes long is not going to be valid, so
limit the input length so we can’t spend too long doing UTF-8 validation
or normalisation.

oss-fuzz#28718

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-18 11:38:31 +00:00
Sebastian Dröge
784f968895 Merge branch '2227-more-nullables' into 'master'
glib: Add more missing return value annotations

See merge request GNOME/glib!1801
2020-12-15 08:22:00 +00:00
Sebastian Dröge
4fb3b6aa37 Merge branch 'asyncqueue-test-timing' into 'master'
tests: Be more lenient with timing checks on asyncqueue pops

See merge request GNOME/glib!1808
2020-12-13 09:18:21 +00:00
Philip Withnall
c58f308aed tests: Be more lenient with timing checks on asyncqueue pops
On heavily loaded CI machines it seems to be taking about 1.3s between
one `g_get_monotonic_time()` call and the next. Allow that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:41:50 +00:00
Philip Withnall
ff56386788 tests: Add some rounding tolerance in timeout test
Occasionally this test fails in CI with the message:
```
assertion failed: (current_time / 1000000 - last_time / 1000000 == 1)
```

The way this calculation is done at the moment, a difference of 1001ms
between `current_time` and `last_time` can result in failure, if the
times are close to a multiple to 1000ms.

Change it to only truncate the result after doing the subtraction, and
add a 500ms tolerance to account for scheduling delays in the test. (For
example, the `test_func()` could be called, then descheduled before it
gets to call `g_get_monotonic_time()`.

Additionally, change the test to use `g_assert_cmpint()` so that future
failures provide more useful debug information.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:41:08 +00:00
Philip Withnall
0755ff97be gchecksum: Drop preconditions for checksum_type being valid
Instead, return `NULL` if the checksum type is unsupported. This may
come in useful if we have to withdraw support for a particular checksum
type in future, due to it being broken.

These semantics were already in place for the return value of
`g_checksum_new()` — see commit 877cc60f and bug
comment https://bugzilla.gnome.org/show_bug.cgi?id=501853#c6.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:30:22 +00:00
Philip Withnall
3fef049472 gchecksum: 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-12 18:30:22 +00:00
Philip Withnall
da83d711d6 gbookmarkfile: 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-12 18:30:22 +00:00
Philip Withnall
7c3891afe9 gasyncqueue: 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-12 18:30:22 +00:00
Philip Withnall
f53b3f3a16 garray: 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-12 18:30:22 +00:00
Philip Withnall
f7dbc6010b tests: Add more tests for GDateTime ISO 8601 seconds parsing
This should add a few more lines/branches to the test coverage.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-11 16:03:11 +00:00
Philip Withnall
50a3d0bf9d gdatetime: Use isnan() instead of !isfinite()
Both are provided by libm, but `isnan()` is provided as a macro, whereas
`isfinite()` is an actual function, and hence libm has to be available
at runtime. That didn’t trivially work on FreeBSD, resulting in this
refactor.

`isfinite(x)` is equivalent to `!isnan(x) && !isinfinite(x)`. The case
of `x` being (negative or positive) infinity is already handled by the
range checks on the next line, so it’s safe to switch to `isnan()` here.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-11 15:39:47 +00:00
Philip Withnall
5d7f4b8f04 gdatetime: Remove floating point from seconds parsing code
Rather than parsing the seconds in an ISO 8601 date/time using a pair of
floating point numbers (numerator and denominator), use two integers
instead. This avoids issues around floating point precision, and also
makes it easier to check for potential overflow from overlong inputs.

This last point means that the `isfinite()` check can be removed, as it
was covering the case where a NAN was generated, which isn’t now
possible using integer arithmetic.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-11 15:36:56 +00:00
Phaedrus Leeds
7ef936f4e3 gfileutils: Fix typo in docs 2020-12-10 21:06:00 -08:00
Sebastian Dröge
68e8fc85b4 Merge branch 'ossfuzz-28473-date-time-iso8601' into 'master'
gdatetime: Disallow NAN as a number of seconds in a GDateTime

See merge request GNOME/glib!1791
2020-12-09 15:12:44 +00:00
Timm Bäder
c2052a4ada array: Avoid sorting 0-sized arrays
Fixes #2264
2020-12-09 14:52:56 +00:00
Philip Withnall
c3805d74ba gdatetime: Disallow NAN as a number of seconds in a GDateTime
The fiendish thing about NAN is that it never compares TRUE against
anything, so the limit checks `seconds < 0.0 || seconds >= 60.0` were
never triggering.

oss-fuzz#28473

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-09 14:50:02 +00:00
Philip Withnall
b4c2e4d553 gdate: Validate input as UTF-8 before parsing
Dates have to be valid UTF-8.

oss-fuzz#28458

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-09 12:07:41 +00:00
Philip Withnall
d5778ec479 gvariant: Clarify operator precedence
This doesn’t change the behaviour of the code, but should squash some
compiler/static analysis warnings about ‘are you sure you got the
precedence right here?’.

Coverity CID: #1159470

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-08 12:17:00 +00:00
Philip Withnall
95c19181ae guri: Correctly set an error when parsing an invalid hostname
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-04 13:54:27 +00:00
Philip Withnall
1d461bc9f4 ghostutils: Abandon hostname conversion early if it’s too long
The `nameprep()` function in `ghostutils.c` is quite complex, and does a
lot of allocations. This means it can take a long time on long hostnames
(on the order of 10KB long). Hostnames should never be that long,
though, so impose some loose length limits.

oss-fuzz#27371

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-04 13:54:27 +00:00
Philip Withnall
3531239f0e ghostutils: Add missing GIR annotations
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-04 13:16:23 +00:00
Philip Withnall
df7f954dd0 tests: Use g_assert_*() rather than g_assert() in hostutils.c
`g_assert()` is compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-04 12:54:11 +00:00
Philip Withnall
23f1a31923 gspawn: Handle ENOSYS from close_range()
It’s possible that GLib will eventually be compiled against a version of
libc which supports `close_range()` (hence `HAVE_CLOSE_RANGE` will be
defined), but then run against an older kernel which doesn’t support it.
In this case, we want to fall back to `fdwalk()`, which should work on
such systems.

This is what cpython does: 3529718925/Python/fileutils.c (L2227)

Spotted by Allison Karlitskaya in !1688.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-03 14:30:29 +00:00
Sebastian Dröge
c27f729752 Merge branch 'extend_p_option_for_tests' into 'master'
Extend the usage of -p option for glib test framework

See merge request GNOME/glib!1738
2020-12-02 08:14:12 +00:00
Frederic Martinsons
3872bf2ccf Introduce new options -r (or --run-prefix) and -x (or --skip-prefix)
They extend the behavior of, respectively, -p and -s options of the
glib test framework

Currently test suite are only run for one level under -p path, for
example, testfilemonitor -p /monitor would execute the following tests:

/monitor/atomic-replace
/monitor/file-changes
/monitor/dir-monitor
/monitor/dir-not-existent
/monitor/cross-dir-moves

With the --run-prefix the sub-test suite file will be executed:

/monitor/atomic-replace
/monitor/file-changes
/monitor/dir-monitor
/monitor/dir-not-existent
/monitor/cross-dir-moves
/monitor/file/hard-links

The --skip-prefix and run-prefix seems symmetrical, but there is a
difference with skip towards run:
--skip-prefix will use a prefix while --run-prefix only work for a valid test path.
For example and for the following test family:

/monitor/atomic-replace
/monitor/file-changes
/monitor/dir-monitor
/monitor/dir-not-existent
/monitor/cross-dir-moves
/monitor/file/hard-links

while --run-prefix /mon will not execute anything, --skip-prefix /mon
 will skip all of these tests.

See #2238 which references this change.
2020-11-30 14:42:58 +01:00
Frederic Martinsons
1d221af7f1 Extends uri test with GstURI inspiration
- Add a test for parsing FILE scheme from uri
It had taken from GST test_protocol_case
- Add a split uri test with encoded spaces in its path
It had taken from GST test_uri_get_location
- Add tests for g_uri_is_valid
It had taken from GST test_uri_misc
Note that the 4 followings uri failed under gst_uri_is_valid but not
under g_uri_is_valid
   B:\\foo.txt
   B:/foo.txt
   B://foo.txt
   B:foo.txt
- Add tests for g_uri_split
It had taken from GST test_url_parsing
- Add tests for test_uri_normalize and test_uri_parsing_relative
The test URI had been taken from GST test_url_normalization
- Add tests for test_uri_iter_params
It had taken from GST test_url_unescape_equals_in_http_query

Closes #2150

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2020-11-30 14:34:06 +01:00
Philip Withnall
0af274faa4 Merge branch 'macos-cross' into 'master'
macos: fix frexpl checks in cross-compilation

See merge request GNOME/glib!1771
2020-11-25 19:11:19 +00:00
Philip Withnall
3088fbae52 Merge branch 'mark_g_assert_as_noreturn_on_MSVC' into 'master'
Adding macros G_NORETURN and G_NORETURN_FUNCPTR

Closes #994

See merge request GNOME/glib!1078
2020-11-25 11:52:23 +00:00
Philip Withnall
9cccc08b82 gmacros: Document soft-deprecation of G_GNUC_NORETURN
It still works, and deprecating it would be quite disruptive (as it’s
used in headers), so amend the documentation to point people to
`G_NORETURN` instead.

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

Helps: #994
2020-11-25 11:37:06 +00:00
Emmanuel Fleury
76426c0158 Rewriting the G_GNUC_NORETURN into G_NORETURN macros everywhere 2020-11-25 11:34:05 +00:00
Emmanuel Fleury
c1d74e35c1 Adding macros G_NORETURN and G_NORETURN_FUNCPTR
This macro is borrowed from the gnulib project in the 'noreturn.h' file.

Fixes: #994
2020-11-25 11:34:05 +00:00
Carlos Garcia Campos
fb838bf3f6 guri: apply scheme normalization flag consistently
For URIs produced in string form, the path should be normalized and port
omitted when the default one is used. When querying the path and port of
a GUri (using getters or g_uri_split()) the normalized path and the
default port should be returned when they were omitted in the parsed URI.

Closes #2257
2020-11-24 14:35:19 +01:00
Andoni Morales Alastruey
64dda3ad87 macos: fix frexpl checks in cross-compilation
Cross-compilation to arm64 for Apple Silicon is not possible
due to the hardcoded settings for frexpl.
See: #1868
2020-11-24 13:05:17 +00:00
Jean Felder
cd6b35f7d2 gdatetime: Fix g_date_time_equal annotation
The parameters C type need to be overriden to GDateTime.
2020-11-24 09:45:58 +00:00
Jean Felder
b513b358a8 gdatetime: Fix g_date_time_hash annotation
The parameter C type needs to be overriden to GDateTime.
2020-11-24 09:45:58 +00:00
Jean Felder
7ec3c26e67 gdatetime: Fix g_date_time_compare annotation
The parameters C type need to be overriden to GDateTime.
2020-11-24 09:45:58 +00:00
Sebastian Dröge
d78778cc46 Merge branch 'scan-build-fixes' into 'master'
Minor scan-build fixes

See merge request GNOME/glib!1770
2020-11-24 09:40:34 +00:00
Philip Withnall
6e446931a8 tests: Add a test to avoid a set-but-unused variable
Spotted by `scan-build`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:21:45 +00:00
Philip Withnall
eafc6b257c tests: Add a test to avoid a set-but-unused variable
Spotted by `scan-build`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:21:45 +00:00
Philip Withnall
6fcc4db228 tests: Drop dead code from GDateTime test
Spotted by `scan-build`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-24 09:21:45 +00:00
Philip Withnall
2237db78f1 tests: Fix GDateTime tests on FreeBSD
`g_time_zone_new_identifier()` returns NULL in the FreeBSD test setup,
presumably because `TZ` isn’t set.

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

Helps: #553
2020-11-24 09:20:28 +00:00
Sebastian Dröge
72360eb8bd Merge branch '553-tz-errors' into 'master'
gtimezone: Add new constructor which can report errors

Closes #553

See merge request GNOME/glib!1760
2020-11-22 08:35:33 +00:00
Philip Withnall
3356934db5 gtimezone: Deprecate g_time_zone_new()
Use `g_time_zone_new_identifier()` instead so you can get error
checking.

Adapt the tests to match.

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

Helps: #553
2020-11-21 23:11:23 +00:00
Sebastian Dröge
fa8a39c6c6 Merge branch 'py-fixes' into 'master'
Python formatting improvements

See merge request GNOME/glib!1757
2020-11-20 18:10:40 +00:00
Philip Withnall
a7c0adbe11 Merge branch 'py-sh-check-fixes' into 'master'
shellcheck fixes

See merge request GNOME/glib!1756
2020-11-20 15:01:59 +00:00
Philip Withnall
c7d2206df3 update-pcre: Use a subshell to avoid cd ..
Shellcheck warning SC2103.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-20 14:48:14 +00:00
Philip Withnall
83e48d8ac1 docs: Document not to use volatile qualifiers
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #600
2020-11-20 14:41:07 +00:00
Philip Withnall
6bd0a4b297 gthread: Use g_atomic() primitives correctly in destructor list
In the Windows destructor list, consistently access
`g_private_destructors` using atomic primitives.

`g_atomic_pointer_compare_and_exchange()` should be equivalent to
`InterlockedCompareExchangePointer()`, but is a bit more understandable
in a general GLib context, and pairs with `g_atomic_pointer_get()`. (I
can’t find a Windows API equivalent for that.)

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

Helps: #600
2020-11-20 14:41:07 +00:00
Philip Withnall
2d03f99ae4 tests: Add comment to volatile atomic tests
`volatile` should not be used to indicate atomic variables, and we
shouldn’t encourage its use. Keep the tests, since they check that we
don’t emit warnings when built against incorrect old code which uses
`volatile`. But add a comment to stop copy/paste use of `volatile`
in the future.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
8a87069ff4 gtypes: Drop volatile qualifier from gatomicrefcount
This is technically an API break, but since the type is meant to be
opaque (third party code is not meant to treat it like an integer) it
should not cause problems.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
eee7e3c668 gmessages: Drop unnecessary volatile qualifiers from macro variables
It’s not necessary and provides no thread safety guarantees.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
1314ff93fc glib: Drop unnecessary volatile qualifiers from internal variables
These variables were already (correctly) accessed atomically. The
`volatile` qualifier doesn’t help with that.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
9474655eb2 gatomic: Drop unnecessary volatile qualifiers from macro variables
It’s not necessary and provides no thread safety guarantees.

The `volatile` qualifiers on the function arguments have to be kept, as
they are (unfortunately) part of the API.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
3c648457c2 gatomic: Drop unnecessary volatile qualifiers from internal variables
It’s not necessary and provides no thread safety guarantees.

The `volatile` qualifiers on the function arguments have to be kept, as
they are (unfortunately) part of the API.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
3dda662beb tests: Drop unnecessary volatile qualifiers from tests
These variables were already (correctly) accessed atomically. The
`volatile` qualifier doesn’t help with that.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
ea746c79fa tests: Fix non-atomic access to a shared variable
And drop the `volatile` qualifier from the variable, as that doesn’t
help with thread safety.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Philip Withnall
a6ce0e742a tests: Fix non-atomic access to a shared variable
And drop the `volatile` qualifier from the variable, as that doesn’t
help with thread safety.

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

Helps: #600
2020-11-20 14:40:19 +00:00
Emmanuele Bassi
6e9ed964c3 Merge branch 'task-trace' into 'master'
Add some tracing to GTask

See merge request GNOME/glib!1629
2020-11-18 13:53:41 +00:00
Sebastian Dröge
56cbdb1a66 Merge branch 'fix_warnings' into 'master'
Fix warnings

See merge request GNOME/glib!1758
2020-11-18 11:53:59 +00:00
Philip Withnall
f9d0135a90 gdatetime: Port to use new g_time_zone_new_identifier() constructor
This allows slightly more reliable error checking on this code path.

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

Helps: #553
2020-11-18 11:31:57 +00:00
Philip Withnall
8105c36e84 gtimezone: Add new constructor which can report errors
Add a new variant of `g_time_zone_new()` which returns `NULL` on
failure to load a timezone, rather than silently returning UTC.

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

Fixes: #553
2020-11-18 11:31:15 +00:00
Emmanuel Fleury
40e70f5d94 Fix several signedness warnings in glib/tests/uri.c
In file included from glib/glib.h:86,
                 from glib/tests/uri.c:25:
glib/gtestutils.h:134:96: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘GConvertError’
  134 |                                                if (!err || (err)->domain != dom || (err)->code != c) \
      |                                                                                                ^~
glib/tests/uri.c:182:9: note: in expansion of macro ‘g_assert_error’
  182 |         g_assert_error (error, G_CONVERT_ERROR, file_to_uri_tests[i].expected_error);
      |         ^~~~~~~~~~~~~~
glib/gtestutils.h:134:96: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘GConvertError’
  134 |                                                if (!err || (err)->domain != dom || (err)->code != c) \
      |                                                                                                ^~
glib/tests/uri.c:220:9: note: in expansion of macro ‘g_assert_error’
  220 |         g_assert_error (error, G_CONVERT_ERROR, file_from_uri_tests[i].expected_error);
      |         ^~~~~~~~~~~~~~
glib/tests/uri.c: In function ‘test_uri_parsing_absolute’:
glib/gtestutils.h:134:96: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘GUriError’
  134 |                                                if (!err || (err)->domain != dom || (err)->code != c) \
      |                                                                                                ^~
glib/tests/uri.c:790:11: note: in expansion of macro ‘g_assert_error’
  790 |           g_assert_error (error, G_URI_ERROR, test->expected_error_code);
      |           ^~~~~~~~~~~~~~
In file included from glib/glibconfig.h:9,
                 from glib/gtypes.h:32,
                 from glib/galloca.h:32,
                 from glib/glib.h:30,
                 from glib/tests/uri.c:25:
glib/tests/uri.c: In function ‘test_uri_iter_params’:
glib/tests/uri.c:1495:51: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘const long int’} and ‘long unsigned int’
 1495 |                 params_tests[i].expected_n_params <= G_N_ELEMENTS (params_tests[i].expected_param_key_values) / 2);
      |                                                   ^~
glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
  941 | #define G_LIKELY(expr) (expr)
      |                         ^~~~
glib/tests/uri.c:1494:7: note: in expansion of macro ‘g_assert’
 1494 |       g_assert (params_tests[i].expected_n_params < 0 ||
      |       ^~~~~~~~
glib/tests/uri.c: In function ‘test_uri_parse_params’:
glib/tests/uri.c:1562:51: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘const long int’} and ‘long unsigned int’
 1562 |                 params_tests[i].expected_n_params <= G_N_ELEMENTS (params_tests[i].expected_param_key_values) / 2);
      |                                                   ^~
glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
  941 | #define G_LIKELY(expr) (expr)
      |                         ^~~~
glib/tests/uri.c:1561:7: note: in expansion of macro ‘g_assert’
 1561 |       g_assert (params_tests[i].expected_n_params < 0 ||
      |       ^~~~~~~~
2020-11-18 12:30:44 +01:00
Emmanuel Fleury
e457df8b8b Fix several signedness warnings in glib/tests/uri.c
glib/tests/uri.c: In function ‘run_file_to_uri_tests’:
glib/tests/uri.c:172:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  172 |   for (i = 0; i < G_N_ELEMENTS (file_to_uri_tests); i++)
      |                 ^
glib/tests/uri.c: In function ‘run_file_from_uri_tests’:
glib/tests/uri.c:197:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  197 |   for (i = 0; i < G_N_ELEMENTS (file_from_uri_tests); i++)
      |                 ^
glib/tests/uri.c: In function ‘run_file_roundtrip_tests’:
glib/tests/uri.c:276:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  276 |   for (i = 0; i < G_N_ELEMENTS (file_to_uri_tests); i++)
      |                 ^
glib/tests/uri.c: In function ‘test_uri_parse_params’:
glib/tests/uri.c:1594:25: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘gssize’ {aka ‘const long int’}
 1594 |           for (j = 0; j < params_tests[i].expected_n_params; j += 2)
      |                         ^
2020-11-18 10:26:12 +01:00
Matt Rose
b23811a234 add __APPLE__ to the list of operating systems that can use sysconf() to get open file limits 2020-11-17 14:42:06 -05:00
Emmanuel Fleury
8aa6e39cc0 Fix several missing initializers in glib/tests/uri.c
glib/tests/uri.c:40:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   40 |   { "/etc", NULL, "file:///etc"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:41:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   41 |   { "/etc", "", "file:///etc"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:42:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   42 |   { "/etc", "otherhost", "file://otherhost/etc"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:51:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   51 |   { "/etc", "localhost", "file://localhost/etc"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:58:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   58 |   { "/etc/\xE5\xE4\xF6", NULL, "file:///etc/%E5%E4%F6" },
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:59:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   59 |   { "/etc/\xC3\xB6\xC3\xA4\xC3\xA5", NULL, "file:///etc/%C3%B6%C3%A4%C3%A5"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:63:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   63 |   { "/etc/file with #%", NULL, "file:///etc/file%20with%20%23%25"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:68:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   68 |   { "/0123456789", NULL, "file:///0123456789"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:69:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   69 |   { "/ABCDEFGHIJKLMNOPQRSTUVWXYZ", NULL, "file:///ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:70:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   70 |   { "/abcdefghijklmnopqrstuvwxyz", NULL, "file:///abcdefghijklmnopqrstuvwxyz"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:71:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   71 |   { "/-_.!~*'()", NULL, "file:///-_.!~*'()"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:77:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   77 |   { "/\"#%<>[\\]^`{|}\x7F", NULL, "file:///%22%23%25%3C%3E%5B%5C%5D%5E%60%7B%7C%7D%7F"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:79:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   79 |   { "/;@+$,", NULL, "file:///%3B@+$,"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:83:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   83 |   { "/:", NULL, "file:///:"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:84:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   84 |   { "/?&=", NULL, "file:///%3F&="},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:86:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   86 |   { "/", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "file://ABCDEFGHIJKLMNOPQRSTUVWXYZ/"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:87:3: error: missing initializer for field ‘expected_error’ of ‘FileToUriTest’
   87 |   { "/", "abcdefghijklmnopqrstuvwxyz", "file://abcdefghijklmnopqrstuvwxyz/"},
      |   ^
glib/tests/uri.c:35:17: note: ‘expected_error’ declared here
   35 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:108:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  108 |   { "file:///etc", "/etc"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:109:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  109 |   { "file:/etc", "/etc"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:119:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  119 |   { "file://localhost/etc", "/etc", "localhost"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:120:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  120 |   { "file://localhost/etc/%23%25%20file", "/etc/#% file", "localhost"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:121:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  121 |   { "file://localhost/\xE5\xE4\xF6", "/\xe5\xe4\xf6", "localhost"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:122:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  122 |   { "file://localhost/%E5%E4%F6", "/\xe5\xe4\xf6", "localhost"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:124:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  124 |   { "file://otherhost/etc", "/etc", "otherhost"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:125:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  125 |   { "file://otherhost/etc/%23%25%20file", "/etc/#% file", "otherhost"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:127:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  127 |   { "file:////etc/%C3%B6%C3%C3%C3%A5", "//etc/\xc3\xb6\xc3\xc3\xc3\xa5", NULL},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:135:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  135 |   { "file:////etc", "//etc"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:136:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  136 |   { "file://///etc", "///etc"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:147:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  147 |   { "file:///c:\\foo", "/c:\\foo"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:148:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  148 |   { "file:///c:/foo", "/c:/foo"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:149:3: error: missing initializer for field ‘expected_hostname’ of ‘FileFromUriTest’
  149 |   { "file:////c:/foo", "//c:/foo"},
      |   ^
glib/tests/uri.c:102:9: note: ‘expected_hostname’ declared here
  102 |   char *expected_hostname;
      |         ^~~~~~~~~~~~~~~~~
glib/tests/uri.c:152:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  152 |   { "file://ABCDEFGHIJKLMNOPQRSTUVWXYZ/", "/", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
glib/tests/uri.c:153:3: error: missing initializer for field ‘expected_error’ of ‘FileFromUriTest’
  153 |   { "file://abcdefghijklmnopqrstuvwxyz/", "/", "abcdefghijklmnopqrstuvwxyz"},
      |   ^
glib/tests/uri.c:103:17: note: ‘expected_error’ declared here
  103 |   GConvertError expected_error; /* If failed */
      |                 ^~~~~~~~~~~~~~
2020-11-17 18:47:17 +01:00
Emmanuel Fleury
766e6325ac Fix several signedness warnings in glib/tests/timer.c
glib/tests/timer.c: In function ‘test_timeval_from_iso8601’:
glib/tests/timer.c:220:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  220 |   for (i = 0; i < G_N_ELEMENTS (tests); i++)
      |                 ^
glib/tests/timer.c: In function ‘test_timeval_to_iso8601’:
glib/tests/timer.c:260:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  260 |   for (i = 0; i < G_N_ELEMENTS (tests); i++)
      |                 ^
2020-11-17 17:25:13 +01:00
Emmanuel Fleury
4c1b068657 Extend the documentation of g_sequence_get_length()
The return value of g_sequence_get_length() is always a
positive number.
2020-11-17 17:25:13 +01:00
Emmanuel Fleury
89729bcd28 Fix several signedness warnings in glib/tests/sequence.c
glib/tests/sequence.c: In function ‘check_integrity’:
glib/tests/sequence.c:139:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’}
  139 |   g_assert (info->n_items == g_queue_get_length (info->queue));
      |                           ^~
glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
  941 | #define G_LIKELY(expr) (expr)
      |                         ^~~~
glib/tests/sequence.c:139:3: note: in expansion of macro ‘g_assert’
  139 |   g_assert (info->n_items == g_queue_get_length (info->queue));
      |   ^~~~~~~~
glib/tests/sequence.c:157:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’}
  157 |   g_assert (info->n_items == g_queue_get_length (info->queue));
      |                           ^~
glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
  941 | #define G_LIKELY(expr) (expr)
      |                         ^~~~
glib/tests/sequence.c:157:3: note: in expansion of macro ‘g_assert’
  157 |   g_assert (info->n_items == g_queue_get_length (info->queue));
      |   ^~~~~~~~
glib/tests/sequence.c: In function ‘run_random_tests’:
glib/tests/sequence.c:554:55: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint’ {aka ‘int’}
  554 |             g_assert (g_queue_get_length (seq->queue) == g_sequence_get_length (seq->sequence));
      |                                                       ^~
glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
  941 | #define G_LIKELY(expr) (expr)
      |                         ^~~~
glib/tests/sequence.c:554:13: note: in expansion of macro ‘g_assert’
  554 |             g_assert (g_queue_get_length (seq->queue) == g_sequence_get_length (seq->sequence));
      |             ^~~~~~~~
glib/tests/sequence.c: In function ‘main’:
glib/tests/sequence.c:1404:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1404 |   for (i = 0; i < G_N_ELEMENTS (seeds); ++i)
      |                 ^
2020-11-17 17:25:03 +01:00
Philip Withnall
d270b6c3db py: Various flake8 cleanups
None of these are particularly significant, but they do get the CI
output clean.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Philip Withnall
905b22a17e py: Reformat all Python files consistently
This commit is the unmodified results of running
```
black $(git ls-files '*.py')
```
with black version 19.10b0. See #2046.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Emmanuel Fleury
82be350f59 Fix signedness warnings in glib/tests/shell.c
glib/tests/shell.c: In function ‘main’:
glib/tests/shell.c:194:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  194 |   for (i = 0; i < G_N_ELEMENTS (cmdline_tests); i++)
      |                 ^
glib/tests/shell.c:201:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  201 |   for (i = 0; i < G_N_ELEMENTS (quote_tests); i++)
      |                 ^
glib/tests/shell.c:208:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  208 |   for (i = 0; i < G_N_ELEMENTS (unquote_tests); i++)
      |                 ^
2020-11-17 14:12:53 +01:00
Emmanuel Fleury
f4bfc50db3 Fix signedness warnings in glib/tests/slice.c
glib/tests/slice.c: In function ‘test_allocate’:
glib/tests/slice.c:146:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  146 |   for (i = 0; i < G_N_ELEMENTS(threads); i++)
      |                 ^
glib/tests/slice.c:149:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
  149 |   for (i = 0; i < G_N_ELEMENTS(threads); i++)
      |                 ^
2020-11-17 14:12:53 +01:00
Emmanuel Fleury
fcbd9d6d75 Fix signedness warning in glib/tests/spawn-singlethread.c
glib/tests/spawn-singlethread.c: In function ‘test_spawn_async_with_fds’:
glib/tests/spawn-singlethread.c:204:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  204 |   for (i = 0; i < G_N_ELEMENTS (tests); i++)
      |                 ^
2020-11-17 14:12:53 +01:00
Emmanuel Fleury
f5b2b8132d Fix signedness warning in glib/guri.c
glib/guri.c: In function ‘should_normalize_empty_path’:
glib/guri.c:756:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
  756 |   for (i = 0; i < G_N_ELEMENTS (schemes); ++i)
      |                 ^
2020-11-17 14:12:53 +01:00