Commit Graph

21105 Commits

Author SHA1 Message Date
Sebastian Dröge
9a5a5c8951 Merge branch 'exact-mtime' into 'master'
g_file_info_get_modification_date_time: Calculate in integer domain

See merge request GNOME/glib!1139
2019-10-02 08:52:40 +00:00
Simon McVittie
14609b0b25 g_file_info_get_modification_date_time: Calculate in integer domain
g_date_time_add_seconds() and g_date_time_add_full() use floating-point
seconds, which can result in the value varying slightly from what's
actually on disk. This causes intermittent test failures in
gio/tests/g-file-info.c on Debian i386, where we set a file's mtime
to be 50µs later, then read it back and sometimes find that it is only
49µs later than the previous value.

I've only seen this happen on i386, which means it might be to do with
different floating-point rounding when a value is stored in the 80-bit
legacy floating point registers rather than in double precision.

g_date_time_add() takes a GTimeSpan, which is in microseconds;
conveniently, that's exactly what we get from the GFileInfo.

Bug-Debian: https://bugs.debian.org/941547
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-10-02 08:30:35 +01:00
Ask Hjorth Larsen
788c01df48 Updated Danish translation 2019-10-02 05:54:08 +02:00
Simon McVittie
42d8e17795 Always build tests if we enabled installed-tests
If we're cross-compiling, the installed-tests are useful even if we
can't run them on the build machine: we can copy them to the host
machine (possibly via a distro package like Debian's libglib2.0-tests)
and run them there.

While I'm changing the build-tests condition anyway, deduplicate it.

Based on a patch by Helmut Grohne.

Bug-Debian: https://bugs.debian.org/941509
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-10-01 20:12:16 +01:00
Ignacio Casal Quinteiro
90bdc2ffb6 Merge branch 'gregistry-key-name-len' into 'master'
gregistrysettings: bump key name length to 2048

See merge request GNOME/glib!1137
2019-10-01 13:03:28 +00:00
Ignacio Casal Quinteiro
9239f2659f gregistrysettings: bump key name length to 128
32 is just too low for key names, specially since the registry has a limit
of 16,383 chars. Giving that, 128 is a good bump for now.
2019-10-01 14:35:43 +02:00
rim
4d362a5afe Update documentation with FreeBSD build instructions 2019-09-30 23:06:53 +03:00
Philip Withnall
eb2125770d tests: Expand g_file_copy() tests to test DEFAULT_PERMS flag
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
67772b6a70 tests: Unconditionally enable the file permissions test
Skip it on systems which don’t support it, rather than compiling it out.
That gives us more information from test runs about which tests are
being run on which architectures.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
bfdc5fc4fc glocalfileinfo: Only return file mode, not type, as UNIX_MODE attribute
As with the previous commit, `st_mode` contains both the file type
(regular file, directory, symlink, special, etc.) and the file mode. For
`G_FILE_ATTRIBUTE_ID_UNIX_MODE`, we only want the file mode — so mask
`st_mode` with `~S_IFMT`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
5dd5269126 glocalfileoutputstream: Only pass file mode, not type, to chmod()
chmod() technically only accepts file modes, not the file type and mode
as returned by stat(). Filter by `S_IFMT` to avoid sending the file
type (regular file, directory, symbolic link, etc.).

In practice, chmod() ignores anything except the file mode, but we might
as well comply with the specification.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
674ba78f12 gfile: Document a few nullable vfuncs
`GFile` always checks whether these vfuncs are `NULL` before calling
them, so document that it’s safe for implementations of `GFile` to not
implement them.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
7d2bce82e2 glocalfile: Don’t define unsupported copy vfunc
The caller assumes that an unimplemented vfunc means that copying is
unsupported (and falls back to its internal copy implementation), so
there’s no point in implementing the vfunc just to unconditionally
return `G_IO_ERROR_NOT_SUPPORTED`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
1b7ab81c1c glocalfile: Don’t define symlink vfunc if it’s unsupported
Rather than defining a vfunc which only ever returns
`G_IO_ERROR_NOT_SUPPORTED`, just don’t define the vfunc at all. The
caller in `GFile` interprets this as symlinks not being supported — so
we get the same behaviour, but without spending a vfunc call on it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
775014dd3b gfile: Use a more specific error message if symlinks are not supported
The string is already translated in `GLocalFile`, so this doesn’t
introduce a new translatable string.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:40:55 +01:00
Philip Withnall
2268f36769 gio-tool: Add a --default-permissions argument to gio copy
This sets the `G_FILE_COPY_DEFAULT_PERMS` flag on the operation,
creating the copied file with default permissions rather than the same
permissions as the source file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #174
2019-09-30 14:40:50 +01:00
Philip Withnall
53f6ede628 gfile: Don’t copy files as private if using default permissions
If a copy operation is started with `G_FILE_COPY_TARGET_DEFAULT_PERMS`,
don’t create the destination file as private. Instead, create it with
the process’ current umask (i.e. ‘default permissions’).

This is a partial re-work of commit d8f8f4d637, with
input from Ondrej Holy.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #174
2019-09-30 14:40:43 +01:00
Philip Withnall
51d73ef5d9 gfile: Factor out flags when copying files
This introduces no functional changes; just reduces duplication in the
code a little.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 14:24:38 +01:00
Sebastian Dröge
c27be686e6 Merge branch '1897-cmpmem-null-handling' into 'master'
gtestutils: Allow cmpmem() arguments to be NULL iff lengths are zero

Closes #1897

See merge request GNOME/glib!1133
2019-09-30 11:53:52 +00:00
Philip Withnall
55997a0aad gtestutils: Allow cmpmem() arguments to be NULL iff lengths are zero
Document this and add a test.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1897
2019-09-30 12:05:55 +01:00
Sebastian Dröge
61509eab26 Merge branch 'python-version' into 'master'
build: Bump Python requirement to ≥ 3.5

See merge request GNOME/glib!1132
2019-09-30 11:05:15 +00:00
Philip Withnall
bbbdc27151 build: Bump Python requirement to ≥ 3.5
We already depend on Meson 0.49.2, which depends on Python 3.5, so we’ve
actually implicitly had this requirement for a while. Might as well make
it explicit.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-30 11:23:20 +01:00
Sebastian Dröge
3ede078e2c Merge branch 'patch-1' into 'master'
gio/gfileinfo: fix param reference in doc comment

See merge request GNOME/glib!1131
2019-09-30 06:09:48 +00:00
David Lechner
2a4b9eb20c gio/gfileinfo: fix param reference in doc comment
The actual parameter name in g_file_attribute_matcher_new()
attributes, so change the param reference to match. This way,
doc tools can create a proper link.
2019-09-29 01:03:22 +00:00
Robert Ancell
349318e8db gutils: Add g_get_os_info()
Add a new function that gets OS information for /etc/os-release.
2019-09-27 15:47:03 +12:00
Philip Withnall
6192fd4cc0 Merge branch 'gspawn' into 'master'
gspawn: Optimize fd closing on AIX and BSDs

Closes #1638

See merge request GNOME/glib!574
2019-09-26 14:01:06 +00:00
Philip Withnall
1097b50c1c gspawn: Retry on EBUSY errors from dup2()
`man dup2` says that on Linux, dup2() can return `EBUSY` if the
operation needs to be retried (in addition to returning `EINTR` in other
cases where it needs to be retried).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-26 14:13:01 +01:00
Philip Withnall
eae72c3597 gspawn: Rewrite some retry loops to use while rather than goto
This introduces no functional changes, but does make the code easier to
understand.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-26 14:10:36 +01:00
Ting-Wei Lan
8af823c8e5 gspawn: Use fdwalk provided by system only when it is known to be safe
All uses of fdwalk in gspawn are between fork and exec, which means only
async-signal safe functions can be called if the parent process has
multiple threads. Since fdwalk is not a standard API, we should not
assume it is safe to use unless the manual of the system explicitly says
it is async-signal safe.

Fixes: #1638
2019-09-26 14:07:32 +01:00
Sebastian Dröge
8af0ba9aad Merge branch 'diagnosticfix' into 'master'
Improve GLIB_DEPRECATED_MACRO_FOR output

See merge request GNOME/glib!1130
2019-09-26 08:01:15 +00:00
Sebastian Dröge
64cd20d590 Merge branch 'android-warning-fix' into 'master'
gdate: Fix tautological comparison warnings on Android

See merge request GNOME/glib!1129
2019-09-26 07:59:19 +00:00
Stephan Bergmann
91cb171057 Improve GLIB_DEPRECATED_MACRO_FOR output
See the mailing list thread <https://lists.fedoraproject.org/archives/list/
devel@lists.fedoraproject.org/thread/SZ676IHHSLOQD6UN2I5J5VKXJ5P5SOVO/>
"glib-2.0 G_CONST_RETURN causing GCC 'warning: const' on F31", where the GCC
diagnostic

> test.c:2:13: warning: const
>     2 | G_CONST_RETURN char * f();
>       |             ^~~~~~~

had confused me, and "Deprecated pre-processor symbol, repace with const" is
probably a better warning message than just "const".

(That recent GCC only prints "Deprecated pre-processor symbol, repace with "
appears to be a bug in GCC that GLIB_UNAVAILABLE_MACRO already suffers from,
too.  Recent Clang correctly prints "Deprecated pre-processor symbol, repace
with const".)
2019-09-26 09:06:30 +02:00
Philip Withnall
2eb3762241 gatomic: Use new __atomic_*() intrinsics for all atomic operations
Previously we used the old `__sync_fetch_*()` intrinsics for some of the
atomic operations, such as `g_atomic_int_compare_and_exchange()`. When
available, use the new `__atomic_*()` intrinsics for those instead.

As with the rest of our use of `__atomic_*()` intrinsics, we use the
`__ATOMIC_SEQ_CST` memory model. If people want to use a less
restrictive memory model to get better performance in certain
situations, they can use the compiler intrinsics directly themselves.
`g_atomic_*()` aim to be as fast as possible while remaining general
purpose.

Tested using:
```
meson test --repeat 1000 atomic atomic-test
```

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1750
2019-09-25 15:48:11 +01:00
Philip Withnall
00c04fdec6 gdate: Fix tautological comparison warnings on Android
Android is emitting `-Wtautological-constant-out-of-range-compare`
warnings when compiling the validation functions for the enum types for
`GDate`. Fix that by comparing as integers.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-25 15:17:37 +01:00
Philip Withnall
02a7af780b Merge branch 'fileinfo-mention-attr-usecs' into 'master'
fileinfo: Mention that usec mtimes are set

See merge request GNOME/glib!1126
2019-09-25 13:43:51 +00:00
Matthew Leeds
1015bfb6ba fileinfo: Mention that usec mtimes are set
g_file_info_set_modification_time() and
g_file_info_set_modification_date_time() set the
G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC attribute in addition to
G_FILE_ATTRIBUTE_TIME_MODIFIED, so microsecond precision is available
when provided by the caller, so mention both attributes in the docs.
2019-09-25 13:43:51 +00:00
Niels De Graef
14ba521b6d gliststore: Add item lookup functions
Currently, there is no quick way to find whether and element is already
part of a list store, except for manually writing a for-loop and calling
`g_list_model_get_item()` and breaking when you find the item.

This is mostly just a small API addition to support this use case.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/1011
2019-09-25 08:37:22 +02:00
Sebastian Dröge
03e3a0396e Merge branch 'ossfuzz-17648-date-uninit-variable' into 'master'
gdatetime: Fix error handling in g_date_time_new_week()

See merge request GNOME/glib!1125
2019-09-24 17:52:15 +00:00
Sebastian Dröge
a96c449d6f Merge branch '1865-variant-get-child-serialisation' into 'master'
gvariant: Handle empty serialisations in get_child_value()

Closes #1865

See merge request GNOME/glib!1043
2019-09-24 17:01:50 +00:00
Philip Withnall
f4dd85628a gdatetime: Fix error handling in g_date_time_new_week()
It was possible to pass in (for example) an invalid year to
g_date_time_new_week(), which would be passed on to g_date_time_new(),
which would (correctly) return `NULL` — but then
g_date_time_get_week_number() would try to dereference that.

Includes a test case.

oss-fuzz#17648

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-24 18:00:53 +01:00
Philip Withnall
a902addf6d Merge branch 'ossfuzz-12960-markup-attribute-limit' into 'master'
gmarkup: Add a limit on the number of attributes in an element

See merge request GNOME/glib!1116
2019-09-24 13:19:35 +00:00
Sebastian Dröge
4170528bd5 Merge branch '1449-atomic-fallback-safety' into 'master'
gatomic: Reorder memory barriers in fallback atomic operations

Closes #1449

See merge request GNOME/glib!1122
2019-09-24 12:50:14 +00:00
Sebastian Dröge
22aed45408 Merge branch 'docs-heading-typo' into 'master'
docs: Fix typo in GConverter{Input,Output}Stream section titles

See merge request GNOME/glib!1124
2019-09-24 12:40:48 +00:00
Philip Withnall
d0964b72db docs: Fix typo in GConverter{Input,Output}Stream section titles
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-24 12:25:10 +01:00
Nirbheek Chauhan
1f8d3451a4 Merge branch '1565-atomic-signs' into 'master'
Fix sign conversion warnings with g_atomic_int_*() calls in GLib

Closes #1565

See merge request GNOME/glib!1121
2019-09-23 14:20:58 +00:00
Nirbheek Chauhan
e3b87b6ffb Merge branch 'add_g_fsync_function' into 'master'
Add a wrapper for fsync() function

Closes #35

See merge request GNOME/glib!1104
2019-09-23 11:22:25 +00:00
Philip Withnall
9a16f2653b gatomic: Reorder memory barriers in fallback atomic operations
If the compiler doesn’t provide modern (C++11) atomic builtins (which is
now quite unlikely), we implement our own using the `__sync_synchronize()`
memory barrier. As Behdad and others have pointed out, though, the
implementation didn’t follow the same semantics as we use with the C++11
builtins — `__ATOMIC_SEQ_CST`.

Fix the use of memory barriers to provide `__ATOMIC_SEQ_CST` semantics.
In particular, this fixes the following common pattern:
```
GObject *obj = my_object_new ();
g_atomic_pointer_set (&shared_ptr, obj);
```

Previously this would have expanded to:
```
GObject *obj = my_object_new ();
*shared_ptr = obj;
__sync_synchronize ();
```

While the compiler would not have reordered the stores to `obj` and
`shared_ptr` within the code on one thread (due to the dependency
between them), the memory system might have made the write to
`shared_ptr` visible to other threads before the write to `obj` — if
they then dereferenced `shared_ptr` before seeing the write to `obj`,
that would be a bug.

Instead, the expansion is now:
```
GObject *obj = my_object_new ();
__sync_synchronize ();
*shared_ptr = obj;
```

This ensures that the write to `obj` is visible to all threads before
any write to `shared_ptr` is visible to any threads. For completeness,
`__sync_synchronize()` is augmented with a compiler barrier to ensure
that no loads/stores can be reordered locally before or after it.

Tested by disabling the C++11 atomic implementation and running:
```
meson test --repeat 1000 atomic atomic-test
```

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1449
2019-09-21 16:16:21 +02:00
Philip Withnall
ec848cb174 tests: Use g_assert_*() in atomic tests rather than g_assert()
`g_assert_*()` provide more useful failure messages, and aren’t compiled
out when building with `G_DISABLE_ASSERT`, unlike `g_assert()`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-09-21 10:54:52 +02:00
Philip Withnall
55f9c6d2f4 gatomic: Add various casts to use of g_atomic_*()s to fix warnings
When compiling GLib with `-Wsign-conversion`, we get various warnings
about the atomic calls. A lot of these were fixed by
3ad375a629, but some remain. Fix them by
adding appropriate casts at the call sites.

Note that `g_atomic_int_{and,or,xor}()` actually all operate on `guint`s
rather than `gint`s (which is what the rest of the `g_atomic_int_*()`
functions operate on). I can’t find any written reasoning for this, but
assume that it’s because signedness is irrelevant when you’re using an
integer as a bit field. It’s unfortunate that they’re named a
`g_atomic_int_*()` rather than `g_atomic_uint_*()` functions.

Tested by compiling GLib as:
```
CFLAGS=-Wsign-conversion jhbuild make -ac |& grep atomic
```

I’m not going to add `-Wsign-conversion` to the set of default warnings
for building GLib, because it mostly produces false positives throughout
the rest of GLib.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1565
2019-09-21 10:48:23 +02:00
Philip Withnall
3ad375a629 Merge branch '1843-tsan-atomic-clang-fix' into 'master'
gatomic: Fix false positive with Clang+TSAN

Closes #1843

See merge request GNOME/glib!1006
2019-09-21 07:56:28 +00:00