Commit Graph

22632 Commits

Author SHA1 Message Date
Emmanuele Bassi
db2cb16e20 docs: Add missing annotation glossary
Without the glossary, gtk-doc will emit warnings for every introspection
annotation it finds.
2020-10-30 16:39:10 +00:00
Philip Withnall
b04a359d1e Merge branch 'mcatanzaro/#2233' into 'master'
gsocketclient: fix crash when async connection step fails

Closes #2233

See merge request GNOME/glib!1728
2020-10-28 16:04:22 +00:00
Michael Catanzaro
c2b8fa8a34 gsocketclient: fix crash when async connection step fails
This is a regression from !1686. The tmp_error is no longer valid after
it is "considered" and cannot be used at this point. We should print the
error earlier instead.

Fixes #2233
2020-10-28 10:43:43 -05:00
Philip Withnall
35ffbf953d Merge branch 'wip/smcv/big-dbus-write-with-fds' into 'master'
gdbus: Cope with sending fds in a message that takes multiple writes

Closes #2074

See merge request GNOME/glib!1725
2020-10-28 13:12:19 +00:00
Philip Withnall
5b0a7ed046 Merge branch 'wip/smcv/dbus-fd-convention' into 'master'
gdbus: Document the intended semantics of handles and fds

See merge request GNOME/glib!1726
2020-10-28 12:40:28 +00:00
Simon McVittie
e5cee9ce5a gio/tests/gdbus-peer: Exercise fds attached to a large message
This incidentally also exercises the intended pattern for sending fds in
a D-Bus message: the fd list is meant to contain exactly those fds that
are referenced by a handle (type 'h') in the body of the message, with
numeric handle value n corresponding to g_unix_fd_list_peek_fds(...)[n].

Being able to send and receive file descriptors that are not referenced by
a handle (as in OpenFile here) is a quirk of the GDBus API, and while it's
entirely possible in the wire protocol, other D-Bus implementations like
libdbus and sd-bus typically don't provide APIs that make this possible.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/2074
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 12:03:59 +00:00
Simon McVittie
fc1f4969bf gdbus: Document the intended semantics of handles and fds
In the D-Bus wire protocol, the handle type (G_VARIANT_TYPE_HANDLE, h)
is intended to be an index/pointer into the implementation's closest
equivalent of GUnixFDList: its numeric value has no semantic meaning
(in the same way that the numeric values of pointers have no semantic
meaning), but a handle with value n acts as a reference to the nth fd
in the fd list.

GDBus provides a fairly direct mapping from the wire protocol to the
C API, which makes it technically possible to attach and use fds
without ever referring to them in the message body, and some
GLib-centric D-Bus APIs rely on this.

However, the other major implementations of D-Bus (libdbus and sd-bus)
transparently replace file descriptors with handles when building
messages, and transparently replace handles with file descriptors when
parsing messages. This means they cannot implement D-Bus APIs that do
not follow the conventional meaning of handles as indexes/pointers into
an equivalent of GUnixFDList.

For interoperability, we should encourage D-Bus API designers to follow
the convention, even though code written against GDBus doesn't strictly
need to do so.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 11:52:22 +00:00
Simon McVittie
70279f8446 gdbus: Cope with sending fds in a message that takes multiple writes
Suppose we are sending a 5K message with fds (so data->blob points
to 5K of data, data->blob_size is 5K, and fd_list is non-null), but
the kernel is only accepting up to 4K with each sendmsg().

The first time we get into write_message_continue_writing(),
data->total_written will be 0. We will try to write the entire message,
plus the attached file descriptors; or if the stream doesn't support
fd-passing (not a socket), we need to fail with
"Tried sending a file descriptor on unsupported stream".

Because the kernel didn't accept the entire message, we come back in.
This time, we won't enter the Unix-specific block that involves sending
fds, because now data->total_written is 4K, and it would be wrong to try
to attach the same fds again. However, we also need to avoid failing
with "Tried sending a file descriptor on unsupported stream" in this
case. We just want to write out the data of the rest of the message,
starting from (blob + total_written) (in this exaple, the last 1K).

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2074
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-28 11:06:52 +00:00
Philip Withnall
2d008e4645 Merge branch 'mcatanzaro/#2221' into 'master'
Fix race in socketclient-slow test

Closes #2221

See merge request GNOME/glib!1711
2020-10-26 15:40:49 +00:00
Sebastian Dröge
4926948aa9 Merge branch 'app-info-docs' into 'master'
gio: Fix some remaining DocBook syntax in a documentation comment

See merge request GNOME/glib!1701
2020-10-26 15:20:03 +00:00
Sebastian Dröge
98f2607006 Merge branch 'dbus-typos' into 'master'
gio: Fix various typos of the name ‘D-Bus’

See merge request GNOME/glib!1722
2020-10-26 15:14:46 +00:00
Philip Withnall
159a9c215a gio: Fix various typos of the name ‘D-Bus’
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-26 14:28:15 +00:00
Michael Catanzaro
1d28fd530c Fix race in socketclient-slow test
This test ensures that g_socket_client_connect_to_host_async() fails if
it is cancelled, but it's not cancelled until after 1 millisecond. Our
CI testers are hitting that race window, and Milan is able to reproduce
the crash locally as well. Switching it from 1ms to 0ms is enough for
Milan to avoid the crash, but not enough for our CI, so let's move the
cancellation to a GSocketClientEvent callback where the timing is
completely deterministic.

Hopefully fixes #2221
2020-10-26 14:18:06 +00:00
Philip Withnall
ec222422c0 Merge branch 'g_main_context_check_skipping_pollrec_updates' into 'master'
gmain: g_main_context_check() can skip updating polled FD sources

Closes #1592

See merge request GNOME/glib!1713
2020-10-26 14:12:04 +00:00
Claudio Saavedra
96ccf06d3d gmain: g_main_context_check() can skip updating polled FD sources
If there is a file descriptor source that has a lower priority
than the one for sources that are going to be dispatched,
all subsequent file descriptor sources (internally sorted by
file descriptor identifier) do not get an update in their GPollRec
and later on wrong sources can be dispatched.

Fix this by first finding the first GPollRec that matches the current
GPollFD, instead of relying on it to be the current one. At
the same time, document the assumptions about the ordering of the
file descriptor records and array and make explicit in the documentation
that the array needs to be passed to g_main_context_check() as it was
received from g_main_context_query().

Added a new test that reproduces the bug by creating two file
descriptor sources and an idle one. Since the first
file descriptor created has a lower identifier and a low priority,
the second one is not dispatched even when it has the same, higher,
priority as the idle source. After fixing this bug, both
higher priority sources are dispatched as expected.

While this patch was written independently, a similar fix for this
bug was first submitted by Eugene M in GNOME/glib!562. Having a
second fix that basically does the same is a reassurance that we
are in the right here.

Fixes #1592
2020-10-26 13:08:01 +00:00
Sebastian Dröge
5339082bbb Merge branch 'improve-g_strrstr_len-docstring' into 'master'
Improve docstrings of 'g_strstr_len' and 'g_strrstr_len'

Closes #2223

See merge request GNOME/glib!1697
2020-10-26 10:51:21 +00:00
Reuben Thomas
3b10a07126 Improve docstrings of 'g_strstr_len' and 'g_strrstr_len' (fixes: #2223)
glib/gstrfuncs.c: clarify the functions’ ability to process
non-nul-terminated strings with a negative 'haystack_length' argument.
2020-10-26 09:26:03 +00:00
Philip Withnall
8f0b968cd1 2.67.0
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-23 16:38:06 +01:00
Emmanuele Bassi
2d812f1ee1 Merge branch 'clang-fixes' into 'master'
gtrace: Add G_GNUC_PRINTF annotation

See merge request GNOME/glib!1718
2020-10-23 14:42:49 +00:00
Emmanuele Bassi
51f30ccb85 Merge branch 'wip/pwithnall/credentials-fix' into 'master'
gmacros: Use __typeof__ when compiling with Clang

See merge request GNOME/glib!1714
2020-10-23 11:41:24 +00:00
Philip Withnall
30782c4c3c gtrace: Add G_GNUC_PRINTF annotation
This allows compilers to check the format placeholders properly. It
fixes compilation on clang, which gives a warning about untrusted
strings being passed on to subsequent functions which require format
placeholders.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-23 12:07:02 +01:00
Philip Withnall
dce24dc449 gmacros: Use __typeof__ when compiling with Clang
Just like gcc, clang has supported `__typeof__` for a long time, so
allow it to be used. This fixes compilation of `gio/gcredentials.c` on
macOS (which uses clang by default).

I don’t know which version clang started supporting `__typeof__` in, so
there’s no version check. One can be added in future if there are
problems.

This fixes commit 5b2bee3f53.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-23 12:04:04 +01:00
Philip Withnall
b67185cd92 Merge branch 'revert-decltype-changes' into 'master'
Revert "Use C++11 decltype where possible"

See merge request GNOME/glib!1712
2020-10-21 11:13:45 +00:00
Philip Withnall
1655dc988c Revert "Use C++11 decltype where possible"
This reverts commit 0d81443ec0.

It breaks WebKit and GJS, so should be reverted for now. These changes
may be reintroduced if a solution can be found for the breakage.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1575#note_940048
2020-10-21 10:51:14 +01:00
Philip Withnall
da2be2e201 Merge branch 'missing-nullable' into 'master'
Add various missing nullable annotations

See merge request GNOME/glib!1706
2020-10-19 11:47:49 +00:00
Sebastian Dröge
c686e1a048 Add various missing nullable annotations 2020-10-19 13:28:46 +03:00
Sebastian Dröge
7b73546ae5 Merge branch 'scan-build-warnings' into 'master'
Fix various minor scan build warnings

See merge request GNOME/glib!1696
2020-10-19 10:26:12 +00:00
Emmanuele Bassi
b5429b7e30 Merge branch 'six-days-to-eom' into 'master'
Fix the 6-days-until-the-end-of-the-month bug

Closes #2215

See merge request GNOME/glib!1683
2020-10-16 13:47:22 +00:00
Руслан Ижбулатов
da00779093 Fix the 6-days-until-the-end-of-the-month bug
The addition causes the date to shift
forward into 1st of the next month, because a 0-based offset
is compared to be "more than" the days in the month instead of "more than
or equal to".

This is triggered by corner-cases where transition date is 6 days
off the end of the month and our calculations put it at N+1th day of the
month (where N is the number of days in the month). The subtraction should
be triggered to move the date back a week, putting it 6 days off the end;
for example, October 25 for CET DST transition; but due to incorrect comparison
the date isn't shifted back, we add 31 days to October 1st and end up
at November 1st).

Fixes issue #2215.
2020-10-16 13:00:49 +00:00
Руслан Ижбулатов
411aa46401 Add a test for the 6-days-until-EOM bug 2020-10-16 13:00:38 +00:00
Philip Withnall
e591d2e4cc Merge branch '2225-slice-getenv-win32' into 'master'
gslice: Inline win32 implementation of g_getenv() to avoid deadlock

Closes #2225

See merge request GNOME/glib!1698
2020-10-16 11:22:02 +00:00
Philip Withnall
4590b4932a gio: Fix some remaining DocBook syntax in a documentation comment
Convert it to Markdown.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-15 16:21:01 +01:00
Philip Withnall
ed00ee3c9e Merge branch 'wip/antoniof/fallback-timezone-cache-lookup' into 'master'
Lookup fallback time zones in the cache to improve performance

Closes #2224 and #2204

See merge request GNOME/glib!1661
2020-10-15 14:54:04 +00:00
Philip Withnall
59add5ecc1 tests: Add a basic test for GTimeZone caching
This tests the previous few commits.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-15 14:43:46 +01:00
António Fernandes
36e7b48ad5 Revert "gtimezone: Cache timezones based on the identifier they were created by"
This reverts commit 851241f19a.

That commit avoids a performance regression but introduces a behavior regression:
changes to /etc/localtime have no effect for the remaining of the application's
runtime.

With the optimization introduced by the previous commit, we can pass NULL to
g_time_zone_new() repeatedly with no performance drawback, so we no longer have
to workaround this case.

Fixes: #2224
2020-10-15 14:43:46 +01:00
António Fernandes
25e634b26b gtimezone: Cache default timezone indefinitely
We cache GTimeZone instances to avoid expensive construction when the
same id is requested again.

However, if the NULL id is passed to g_time_zone_new(), we always
construct a new instance for the default/fallback timezone.

With the recent introduction of some heavy calculations[1], repeated
instance construction in such cases has visible performance impact in
nautilus list view and other such GtkTreeView consumers.

To avoid this, cache reference to a constructed default timezone and
use it the next time g_time_zone_new() is called with NULL argument,
as long as the default identifier doesn't change. We already did the
same for the local timezone[2].

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2204

Based on idea proposed by Sebastian Keller <skeller@gnome.org>.

[1] 25d950b61f
[2] 551e83662d
2020-10-15 14:43:46 +01:00
Philip Withnall
b538cb0c8c gslice: Inline win32 implementation of g_getenv() to avoid deadlock
The win32 implementation of `g_getenv()` uses GSlice (from within
GQuark), which results in a deadlock when examining the `G_SLICE`
environment variable.

Fix that by inlining a basic implementation of `g_getenv()` at that call
site.

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

Fixes: #2225
2020-10-15 10:43:28 +01:00
Philip Withnall
e2e8339e0a Merge branch 'typeof' into 'master'
Use C++11 decltype where possible

See merge request GNOME/glib!1575
2020-10-15 08:52:47 +00:00
Xavier Claessens
0d81443ec0 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]
2020-10-14 14:52:41 -04:00
Xavier Claessens
3028e6a967 gmem.h: Simplify condition where typeof is available 2020-10-14 14:52:32 -04:00
Xavier Claessens
a1847d0d03 gatomic: Check if glib_typeof() is defined before using it 2020-10-14 14:48:40 -04:00
Xavier Claessens
5b2bee3f53 Replace __typeof__ with glib_typeof macro
g_has_typeof macro is wrongly in the public g_ namespace, internaly
symbols are usually in the glib_ namespace. This will also allow to
define glib_typeof differently on non-GNUC compilers (e.g. c++11
decltype).
2020-10-14 14:48:36 -04:00
Philip Withnall
31bca17f52 Merge branch 'fix_warnings' into 'master'
Fix warnings (keep going)

See merge request GNOME/glib!1647
2020-10-14 14:10:05 +00:00
Emmanuel Fleury
dfa4907072 Fix signedness warning in glib/tests/fileutils.c
glib/gtestutils.h:134:96: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘GFileError’
  134 |                                                if (!err || (err)->domain != dom || (err)->code != c) \
      |                                                                                                ^~
glib/tests/fileutils.c:1072:15: note: in expansion of macro ‘g_assert_error’
 1072 |               g_assert_error (error, G_FILE_ERROR, tests[i].expected_error);
      |               ^~~~~~~~~~~~~~
2020-10-14 14:17:09 +02:00
Emmanuel Fleury
019c6746db Fix several signedness warnings in glib/tests/array-test.c
glib/tests/array-test.c: In function ‘array_remove_index’:
glib/tests/array-test.c:388:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  388 |   for (i = 0; i < garray->len; i++)
      |                 ^
glib/tests/array-test.c: In function ‘array_remove_index_fast’:
glib/tests/array-test.c:425:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  425 |   for (i = 0; i < garray->len; i++)
      |                 ^
glib/tests/array-test.c: In function ‘array_remove_range’:
glib/tests/array-test.c:462:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  462 |   for (i = 0; i < garray->len; i++)
      |                 ^
glib/tests/array-test.c: In function ‘array_sort’:
glib/tests/array-test.c:604:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  604 |   for (i = 0; i < garray->len; i++)
      |                 ^
glib/tests/array-test.c: In function ‘array_sort_with_data’:
glib/tests/array-test.c:636:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
  636 |   for (i = 0; i < garray->len; i++)
      |                 ^
glib/tests/array-test.c: In function ‘byte_array_sort’:
glib/tests/array-test.c:1876:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1876 |   for (i = 0; i < gbarray->len; i++)
      |                 ^
glib/tests/array-test.c: In function ‘byte_array_sort_with_data’:
glib/tests/array-test.c:1904:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1904 |   for (i = 0; i < gbarray->len; i++)
      |                 ^
2020-10-14 14:17:09 +02:00
Emmanuel Fleury
d6eaa742e7 Fix signedness warnings in glib/tests/convert.c
glib/tests/convert.c:168:16: error: comparison of integer expressions
of different signedness: ‘glong’ {aka ‘long int’} and ‘size_t’
{aka ‘long unsigned int’}

  168 |   if (utf8_len == strlen (utf8))
      |                ^~

glib/tests/convert.c:309:16: error: comparison of integer expressions
of different signedness: ‘glong’ {aka ‘long int’} and ‘size_t’
{aka ‘long unsigned int’}

  309 |   if (utf8_len == strlen (utf8))
      |                ^~
2020-10-14 14:17:09 +02:00
Emmanuel Fleury
fd7f2e6c8a Fix several signedness problems in glib/tests/checksum.c
glib/tests/checksum.c:1079:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1079 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~

glib/tests/checksum.c:1103:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1103 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~
glib/tests/checksum.c:1187:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1187 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~
glib/tests/checksum.c:1192:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1192 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~
glib/tests/checksum.c:1197:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1197 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~
glib/tests/checksum.c:1202:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1202 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~
glib/tests/checksum.c:1207:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
 1207 |   for (length = 0; length <= FIXED_LEN; length++)
      |                           ^~
2020-10-14 14:17:09 +02:00
Emmanuel Fleury
5a361aeeaa Fix signedness warning in glib/tests/base64.c
glib/tests/base64.c:28:20: error: comparison of integer expressions of
different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘gint’ {aka ‘int’}

   28 |   while (input_len < length)
      |                    ^
2020-10-14 14:17:09 +02:00
Philip Withnall
e9c4e19950 tests: Add additional keyfile assertions
These slightly improve the tests but, more importantly, squash a
scan-build warning about assigning to a variable which is never
subsequently used:
```
../../../glib/tests/keyfile.c:1150:3: warning: Value stored to 'value' is never read
  value = g_key_file_get_string (keyfile, "a", "key=", &error);
  ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../glib/tests/keyfile.c:1159:3: warning: Value stored to 'value' is never read
  value = g_key_file_get_string (keyfile, "a", "key[", &error);
  ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../glib/tests/keyfile.c:1176:3: warning: Value stored to 'value' is never read
  value = g_key_file_get_string (keyfile, "a", " key", &error);
  ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-14 13:15:14 +01:00
Philip Withnall
0544efcbb4 tests: Improve signed int handling to silence scan-build warnings
This should silence the following warning:
```
../../../glib/tests/mutex.c:206:5: warning: 1st function call argument is an uninitialized value
    g_thread_join (threads[i]);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-14 13:15:09 +01:00