Commit Graph

30798 Commits

Author SHA1 Message Date
Philip Withnall
4d31fe6b7d
gnulib: Disable -Wfloat-conversion by default
gnulib doesn’t work with it, and if we try and enable it then mingw
versions of `signbit()` start causing problems.

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

Helps: #3405
2024-06-28 16:34:08 +01:00
Philip Withnall
7b435dfa7c
garray: Fix g_ptr_array_insert() with indices > G_MAXINT
While an index greater than `G_MAXINT` can’t be passed to
`g_ptr_array_insert()`, `-1` can be — and if that’s done with an array
which has more than `G_MAXINT` elements in it, the new element will be
inserted part-way through the array rather than being appended.

Spotted by building with `-Wsign-conversion`.

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

Helps: #3405
2024-06-28 15:27:25 +01:00
Philip Withnall
b32e1b63ee
gqsort: Add g_sort_array() and deprecate g_qsort_with_data()
The latter only accepts a `gint` as the number of elements in the array,
which means that its use in `GArray` (and related array implementations)
truncates at least half the potential array size.

So, introduce a replacement for it which uses `size_t` for the number of
elements. This is inline with what `qsort()` (or `qsort_r()`) actually
does. Unfortunately we can’t directly use `qsort_r()` because it’s not
guaranteed to be a stable sort.

This fixes some `-Wsign-conversion` warnings (when building GLib with
that enabled).

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

Helps: #3405
2024-06-28 15:27:18 +01:00
Philip Withnall
692a50b78e
build: Enable -Wfloat-conversion by default
GLib now compiles without emitting any float conversion warnings, so
let’s keep it that way.

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

Helps: #3405
2024-06-28 14:44:01 +01:00
Philip Withnall
e35cfef509
performance: Add explicit casts for some double → other numeric type conversions
If we enable `-Wfloat-conversion`, these warn about a possible loss of
precision due to an implicit conversion from `double` to some other
numeric type.

The warning is correct: there is a possible loss of precision here. In
these instances, we don’t care, as the floating point arithmetic is
being done to do some imprecise scaling or imprecise timing. A loss of
precision is not a problem.

So, add an explicit cast to squash the warning.

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

Helps: #3405
2024-06-28 14:43:26 +01:00
Philip Withnall
b7153f5072
performance: Fix signedness of ints throughout
The tests were using a lot of signed `int`s when actually the values
being handled were always non-negative. Use `unsigned int` consistently
throughout.

Take the opportunity to move declarations of loop iterator variables
into the loops.

This introduces no functional changes.

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

Helps: #3405
2024-06-28 14:41:48 +01:00
Philip Withnall
6129f6f244
tests: Use correct numeric comparison assertions in param tests
There were various places where (signed or unsigned) integer assertions
were being used to compare `double` or `float` values, resulting in an
implicit integer conversion.

This causes a warning when building with `-Wfloat-conversion`.

Improve the specificity of the tests by using the most-specific numeric
assertions through all `param` tests.

For the conversion tests, this means using the assertion function
associated with the target type, not the source type.

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

Helps: #3405
2024-06-28 14:38:22 +01:00
Philip Withnall
665292006e
gvalue: Add explicit casts in numeric transform functions
Compiling with `-Wfloat-conversion` warns about a few implicit
conversions from `double`/`float` to other numeric types in the `GValue`
transform functions.

These warnings are correct: value transformations can result in loss of
precision. That loss of precision is understood and expected, so add
some explicit casts to squash the warnings.

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

Helps: #3405
2024-06-28 14:35:57 +01:00
Philip Withnall
cdbfef3842
gparamspecs: Define G_FLOAT_EPSILON as a float constant
Rather than defining it as a double constant. This introduces no
functional changes, but does squash some `-Wfloat-conversion` warnings.

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

Helps: #3405
2024-06-28 14:35:00 +01:00
Philip Withnall
b69fe111ec
tests: Use a correct-typed constant in gdatetime tests
This makes no functional changes, but does avoid a warning from
`-Wfloat-conversion` due to implicitly switching from `guint64` to
`gdouble` and then back to `guint64`.

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

Helps: #3405
2024-06-28 14:34:04 +01:00
Philip Withnall
412aed7c70
gtestutils: Add some explicit double casts
This avoids some false positive warnings from `-Wfloat-conversion`.

The code in `gtestutils.c` is a bit odd: it uses an array of `long
double` elements, with specific indices of that array storing specific
meaningful numbers, each of which has a type which is representable as a
`long double`, but which actually isn’t.

This is a prime candidate for refactoring to not use such a type-unsafe
API where everything is marshalled through `long double`. Unfortunately,
the array is declared in `GTestLogMsg`, which is defined in the public
`gtestutils.h` header, so we can’t change it. Boo.

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

Helps: #3405
2024-06-28 14:31:18 +01:00
Philip Withnall
d0cba9e6ec
girnode: Explicitly lose precision on parsed float values
When building a typelib, the values of constants need to be converted
from a string format (from the GIR) to a binary format. This is
currently done, for all numeric types, using `g_ascii_strto*()`
functions, but with minimal validation. String values which are not
representable as binary numbers are either silently truncated or
clamped.

`-Wfloat-conversion` has flagged that this happens for floats – a
double-precision return from `g_ascii_strtod()` is implicitly cast down
to a float.

While we should ideally have some better error handling so that
conversion to a typelib fails if a constant is not representable in the
typelib, this is a problem for *all* numeric types and not just `float`,
so add an explicit cast to ignore the error for now.

In practice there probably isn’t a problem for any numeric types here,
as there should be validation of the string value when the GIR is
generated anyway.

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

Helps: #3405
2024-06-28 14:27:23 +01:00
Philip Withnall
ebe609eeef
tests: Rearrange double/int comparisons in srvtarget to avoid casts
By keeping `expected` as a `double` for longer, we avoid having to cast
when populating the elements of `ordering`, to avoid
`-Wfloat-conversion` warnings.

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

Helps: #3405
2024-06-28 14:25:38 +01:00
Philip Withnall
2713255574
glib: Add explicit casts for some double → other numeric type conversions
If we enable `-Wfloat-conversion`, these warn about a possible loss of
precision due to an implicit conversion from `double` to some other
numeric type.

The warning is correct: there is a possible loss of precision here. In
these instances, we don’t care, as the floating point arithmetic is
being done to do some imprecise scaling or imprecise timing. A loss of
precision is not a problem.

So, add an explicit cast to squash the warning.

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

Helps: #3405
2024-06-28 14:24:55 +01:00
Philip Withnall
ad5948bbf5
gparamspecs: Fix loss of precision when validating a double-typed pspec
As spotted by `-Wfloat-conversion`. Doubles which could not be
accurately represented as floats may have erroneously failed bounds
validation.

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

Helps: #3405
2024-06-28 14:24:39 +01:00
Philip Withnall
616749c1e2
2.81.0
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-28 12:25:56 +01:00
Philip Withnall
935dd89622 Merge branch '3401-gir-scanner-deps' into 'main'
introspection: Add libgirepository as a dep to all generate_gir() calls

Closes #3401

See merge request GNOME/glib!4122
2024-06-27 09:14:45 +00:00
Michael Catanzaro
22c6aa9407 Merge branch 'allow-null-buffer-zero-count-output-stream-write' into 'main'
g_output_stream_write: Allow NULL buffer if count is 0

Closes #3402

See merge request GNOME/glib!4123
2024-06-26 18:57:29 +00:00
Gary Li
d64336e1a9 g_output_stream_write: Allow NULL buffer if count is 0
We currently fail a buffer != NULL assertion if buffer is NULL and count is 0. Allow this case without critical assertions.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3402
2024-06-26 14:18:41 -04:00
Philip Withnall
e2a36f8b05 Merge branch 'free' into 'main'
gtestutils: Free test_data when freeing a test case

See merge request GNOME/glib!4120
2024-06-26 12:45:05 +00:00
Philip Withnall
98854efa74
introspection: Add libgirepository as a dep to all generate_gir() calls
libgirepository is not needed by most of the modules, but it is needed
by the `g-ir-scanner` generated dumper program. If we don’t explicitly
include the local version of it here, Meson will implicitly link against
it anyway, and that might pull in a different version, or try to link
against a half-built local version as the build ordering dependency tree
won’t reflect this relationship.

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

Fixes: #3401
2024-06-26 12:48:32 +01:00
Philip Withnall
5deab5f0f1 Merge branch 'macros' into 'main'
RFC: gmacros: Avoid casting functions

See merge request GNOME/glib!4121
2024-06-26 11:26:35 +00:00
Akihiko Odaki
0e994ead0f gtestutils: Free test_data when freeing a test case
Commit 9dad94e7q ensured `test_data` is freed when a test is skipped,
but didn't ensure that when a whole test suite is skipped.

We are assuming the ownership of `test_data` is passed to GTestCase
with `g_test_add_data_func_full()` so free `test_data` always when
freeing a test case.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
2024-06-26 20:02:18 +09:00
Akihiko Odaki
328d996fbe gmacros: Avoid casting functions
gmacros.h casts functions to GDestroyNotify, which prevents enabling the
following hardening options in applications: -fsanitize=address
-fsanitize=cfi-icall (without -fsanitize-cfi-icall-generalize-pointers),
and -Wcast-function-type-strict.

Define another inline function that warps the original function into
GDestroyNotify.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
2024-06-26 19:59:55 +09:00
Philip Withnall
07fa7b261c Merge branch 'trashing-long-file-name' into 'main'
GLocalFile: support trashing long file name

See merge request GNOME/glib!3697
2024-06-19 10:11:50 +00:00
rong wang
478127e074 GLocalFile: support trashing long file name
When the file name is too long (for example, more than 238 bytes on
ext4), this will cause the creation of the .trashinfo file to fail.
Let's shorten the .trashinfo filename in this case, after all the
trash specification only requires unique filenames (see
`Contents of a trash directory` section in
https://specifications.freedesktop.org/trash-spec/trashspec-latest.html).
2024-06-19 10:27:33 +01:00
Philip Withnall
fd4b61d8fb Merge branch 'wip/pwithnall/file-load-contents-i386' into 'main'
tests: Improve 4GB file loading test to work on i386

See merge request GNOME/glib!4117
2024-06-18 19:53:38 +00:00
Philip Withnall
cce6ca8c88
tests: Improve 4GB file loading test to work on i386
This should test the limits of loading 4GB files on i386 platforms, such
as the Hurd CI runner. On such platforms, `sizeof(size_t) == 4`.

This should fix the compiler warning from
https://gitlab.gnome.org/GNOME/glib/-/jobs/3989442:
```
../gio/tests/file.c:2931:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
 2931 | static const gsize testfile_4gb_size = ((gsize) 1 << 32) + (1 << 16); /* 4GB + a bit */
      |                                                   ^~
cc1: all warnings being treated as errors
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 12:58:51 +01:00
Michael Catanzaro
496d8a164c Merge branch 'wip/otte/large-files' into 'main'
Handle files >4GB in g_file_load_contents()

Closes #3397

See merge request GNOME/glib!3373
2024-06-17 15:44:37 +00:00
Philip Withnall
1f838b061b
tests: Skip >4GB file tests unless running tests in slow/thorough mode
They take too long to include in a normal test run. They’ll still be run
in CI once a week as part of our scheduled slow test job.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-17 13:03:08 +01:00
Philip Withnall
a8be45204e tests: Fix a typo in a test name in the file test suite
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-17 13:03:05 +01:00
Benjamin Otte
e74294473e tests: Add test for >4GB reads with g_file_load_contents()
The tests - one for sync, one for async - create a sparse file for
this purpose, so this should be cheap on the fileystem.

Of course, the test still allocates >4GB of memory for the data that it
returns from g_file_load_contents(), I hope the CI test runners can deal
with that.
2024-06-17 13:03:05 +01:00
Benjamin Otte
77c35415a3 tests: Use g_clear_fd() 2024-06-17 13:03:05 +01:00
Benjamin Otte
e8254f14fd gfile: Rewrite load_contents() to use realloc()
GByteArray is limited to 4GB in size and the current code silently
overflows when that happens.

Replace both load_contents() and load_contents_async() implementations
with a version that uses realloc() and gsize to maintain the array.
2024-06-17 13:03:05 +01:00
Benjamin Otte
a57f0b190a array: Abort on overflow
This is a precautionary assert that will probably only trigger on 32bit
OSes. But g_nearest_pow() can overflow.
2024-06-17 11:51:00 +01:00
Michael Catanzaro
bce073dca1 Merge branch 'notification-test-asserts' into 'main'
tests: Use g_assert_*() rather than g_assert() in notification tests

See merge request GNOME/glib!4115
2024-06-14 22:29:09 +00:00
Philip Withnall
577ad8d07d
tests: Use g_assert_*() rather than g_assert() in notification tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-14 23:05:25 +01:00
Martin
9fa69b3a72 Update Slovenian translation 2024-06-14 20:10:04 +00:00
Philip Withnall
e89e0a342c Merge branch '3254-construct-property-deprecation' into 'main'
gobject: Don’t warn when setting deprecated construct property defaults

Closes #3254

See merge request GNOME/glib!3942
2024-06-14 19:16:42 +00:00
Philip Withnall
a78c80e9ab Merge branch 'win32-localfileinfo-fixes' into 'main'
glocalfileinfo: A few fixes on win32

See merge request GNOME/glib!4114
2024-06-14 17:25:13 +00:00
Philip Withnall
df5aa217e4
gobject: Don’t warn when setting deprecated construct property defaults
The default values for construct properties always have to be set, even
if those properties are deprecated. The code to do that is in GLib, and
not under the control of the user (unless they completely override the
`constructor` vfunc, which is not recommended). So don’t emit a warning
for that if `G_ENABLE_DIAGNOSTICS` is enabled.

In particular, this fixes deprecation warnings being emitted for
properties of a parent class when chaining up with a custom constructor,
even when none of the child class code mentions the deprecated property.

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

Fixes: #3254
2024-06-14 17:53:37 +01:00
Luca Bacci
2cf0ce39aa glocalfileinfo: Use stat results only if stat succeeded 2024-06-14 17:42:39 +01:00
Luca Bacci
3ae88886ac glocalfileinfo: Do not set G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP twice 2024-06-14 17:42:39 +01:00
Philip Withnall
15202c970a Merge branch 'bootstrap-tests' into 'main'
tests: skip tests that will fail due to missing dependencies

Closes #3317

See merge request GNOME/glib!3997
2024-06-14 15:56:38 +00:00
Natanael Copa
2c042cd466 tests: find update-desktop-database
Disable tests that require update-desktop-database when it is missing.

It requires glib to build so it will be missing when bootstrapping glib.

Refactor the ifdef for Windows and MacOS while at it and reduce number
of ifdefs.

Ref: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3658
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-06-14 16:35:44 +01:00
Natanael Copa
7322a925e2 tests: skip tests that requires dbus-daemon when its missing
dbus may not be built yet during bootstrap, because it needs glib to
build.

Ref: https://gitlab.gnome.org/GNOME/glib/-/issues/3317
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-06-14 16:35:44 +01:00
Natanael Copa
6a262b0c03 tests: skip test that requires shared-mime-info when its missing
shared-mime-info required glib to build and will not be there during
bootstrap. Skip the test if it is missing.

ref: https://gitlab.gnome.org/GNOME/glib/-/issues/3317
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-06-14 16:35:44 +01:00
Philip Withnall
5fdd6507b4 Merge branch 'ebassi/c11-toolchain-req-docs' into 'main'
docs: Update toolchain requirement to C11

See merge request GNOME/glib!4082
2024-06-14 12:35:06 +00:00
Marco Trevisan (Treviño)
5b0ae99e9a build: Add -Wno-typedef-redefinition to CFLAGS
Without the -Wno-typedef-redefinition option, clang complains if a typedef
gets redefined in gnu99 mode (since this is officially a C11 feature). This
also happened with old versions of GCC.

So, don't break the build on such warn, since we want to support
toolchains that supports C11 anyways.
2024-06-14 12:35:21 +01:00
Emmanuele Bassi
5697c11f1f docs: Update toolchain requirement to C11
We have required C99 for a while; in the meantime, most C toolchains
have moved on to C11 or later as the default C standard.

We still allow for C99 toolchains, but in the future we are going to
require a C11 toolchain to build and use GLib.
2024-06-14 12:35:21 +01:00