Commit Graph

22339 Commits

Author SHA1 Message Date
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
Sebastian Dröge
58d5b27ec5 Merge branch 'file-replace-contents-refcounting' into 'master'
gfile: Clarify refcount handling for g_file_replace_contents_bytes_async()

See merge request GNOME/glib!1695
2020-10-14 11:45:48 +00:00
Philip Withnall
730a395701 Merge branch 'strv-builder' into 'master'
gstrvbuilder: Add a new object to make NULL-terminated string arrays.

See merge request GNOME/glib!1417
2020-10-14 11:01:24 +00:00
Robert Ancell
b2cc8d1740 gstrvbuilder: Add a new object to make NULL-terminated string arrays.
GLib uses NULL-terminated string arrays (GStrv) in a number of places, however
these are quite hard to construct in C when the number of elements is not known
in advance. GStrvBuilder wraps GPtrArray to make these easy to create with
type safety and does the memory management for you.
2020-10-14 11:01:24 +00:00
Philip Withnall
2996d0d689 gfile: Clarify refcount handling for g_file_replace_contents_bytes_async()
This introduces no functional changes, but makes the refcount handling a
little easier to follow by no longer splitting a ref/unref pair across
three callbacks. Now, the ref/unref pairs are all within function-local
scopes.

Coverity CID: #1430783

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-14 11:50:42 +01:00
Philip Withnall
06587fbfd7 Merge branch 'mcatanzaro/#2211' into 'master'
Various improvements in GSocketClient

Closes #2211 and #1994

See merge request GNOME/glib!1686
2020-10-14 10:20:07 +00:00
Sebastian Dröge
f241b96914 Merge branch 'wip/fix-handler-leak' into 'master'
gsignal: Plug g_signal_connect_object leak

See merge request GNOME/glib!1692
2020-10-13 15:18:52 +00:00
Sebastian Dröge
9c73f8b528 Merge branch 'benzea/fix-possible-source-locking-issue' into 'master'
gmain: Fix possible locking issue in source unref

See merge request GNOME/glib!1691
2020-10-13 13:49:43 +00:00
Ray Strode
d691c2ebd2 gsignal: Plug g_signal_connect_object leak
commit 916297be79 added a hash table
to provide constant time lookups of signal handlers.

Unfortunately, that commit neglected to remove handlers from
g_signal_connect_object calls from the hash table that are
disconnected implicitly when the associated object goes away.

This commit addresses that bug by changing the closure invalidate
handler associated with the signal connection to properly remove the
handler from the hash table.
2020-10-13 09:49:29 -04:00
Benjamin Berg
bf814a9aa3 gmain: Fix possible locking issue in source unref
When unref'ing child sources, the lock is already held. But instead of
passing TRUE to g_source_unref_internal it currently passes whether the
lock was already held outside of the current invocation. Just pass TRUE
to fix this possible issue.
2020-10-13 15:12:37 +02:00
Dušan Kazik
2954754cb3 Update Slovak translation
(cherry picked from commit 0e8066e350)
2020-10-13 12:43:48 +00:00
Philip Withnall
0dfef13ba7 Merge branch 'add_close_in_parent_flag' into 'master'
gsubprocesslauncher: Allow to close FDs

See merge request GNOME/glib!1677
2020-10-13 08:30:57 +00:00
Sebastian Dröge
88deca52c0 Merge branch 'uri-nullable' into 'master'
uri: add missing (not)nullable annotations

See merge request GNOME/glib!1687
2020-10-13 07:39:44 +00:00
Marc-André Lureau
2306f96fb0 uri: add missing (not)nullable annotations
As suggested by Sebastian Dröge:
https://github.com/gtk-rs/glib/pull/697#pullrequestreview-505797722

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-10-13 09:59:28 +03:00
Sebastian Dröge
59b71837a5 Merge branch 'spawn-close_range' into 'master'
gspawn: Use close_range() if available to close FDs between fork/exec

See merge request GNOME/glib!1688
2020-10-13 06:52:10 +00:00
Sergio Costas
c12762a091 GSubprocessLauncher: allow to close passed FDs
By default, when using g_subprocess_launcher_take_fd() to pass an
FD to a child, the GSubprocessLauncher object also takes ownership
of the FD in the parent, and closes it during finalize(). This is
a reasonable assumption in the majority of the cases, but sometimes
it isn't a good idea.

An example is when creating a GSubprocessLauncher in JavaScript:
here, the destruction process is managed by the Garbage Collector,
which means that those sockets will remain opened for some time
after all the references to the object has been droped. This means
that it could be not possible to detect when the child has closed
that same FD, because in order to make that work, both FDs
instances (the one in the parent and the one in the children) must
be closed. This can be a problem in, as an example, a process that
launches a child that communicates with Wayland using an specific
socket (like when using the new API MetaWaylandClient).

Of course, it isn't a valid solution to manually call close() in
the parent process just after the call to spawn(), because the FD
number could be reused in the time between it is manually closed,
and when the object is destroyed and closes again that FD. If that
happens, it will close an incorrect FD.

One solution could be to call run_dispose() from Javascript on the
GSubprocessLauncher object, to force freeing the resources.
Unfortunately, the current code frees them in the finalize()
method, not in dispose() (this is fixed in !1670 (merged) ) but it
isn't a very elegant solution.

This proposal adds a new method, g_subprocess_launcher_close(),
that allows to close the FDs passed to the child. To avoid problems,
after closing an FD with this method, no more spawns are allowed.

Fix: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1677
2020-10-12 20:29:48 +02:00
Philip Withnall
9f8ccee65f gspawn: Use close_range() if available to close FDs between fork/exec
It’s landed in kernel 5.9: http://lkml.iu.edu/hypermail/linux/kernel/2008.0/02649.html

Note, this is untested because I currently don’t have kernel 5.9. We can
fix anything up if it breaks once the new syscall is wrapped in glibc.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-12 18:10:45 +01:00
Cheng-Chia Tseng
8cefc0ae1e Update Chinese (Taiwan) translation
(cherry picked from commit 3248b7b670)
2020-10-12 14:57:18 +00:00
Juliano de Souza Camargo
5af7ed8d85 Update Portuguese translation
(cherry picked from commit 794af4ee4b)
2020-10-11 14:29:46 +00:00
Michael Catanzaro
b88b3712e0 gsocketclient: return best errors possible
Originally, GSocketClient returned whatever error occured last. Turns
out this doesn't work well in practice. Consider the following case:
DNS returns an IPv4 and IPv6 address. First we'll connect() to the
IPv4 address, and say that succeeds, but TLS is enabled and the TLS
handshake fails. Then we try the IPv6 address and receive ENETUNREACH
because IPv6 isn't supported. We wind up returning NETWORK_UNREACHABLE
even though the address can be pinged and a TLS error would be more
appropriate. So instead, we now try to return the error corresponding
to the latest attempted GSocketClientEvent in the connection process.
TLS errors take precedence over proxy errors, which take precedence
over connect() errors, which take precedence over DNS errors.

In writing this commit, I made several mistakes that were caught by
proxy-test.c, which tests using GSocketClient to make a proxy
connection. So although adding a new test to ensure we get the
best-possible error would be awkward, at least we have some test
coverage for the code that helped avoid introducing bugs.

Fixes #2211
2020-10-09 10:50:22 -05:00
Michael Catanzaro
14f7b5e590 gsocketclient: Crash on error if error is missing
We should never return unknown errors to the application. This would be
a glib bug.

I don't think it's currently possible to hit these cases, so asserts
should be OK. For this to happen, either (a) a GSocketAddressEnumerator
would have to return NULL on its first enumeration, without returning an
error, or (b) there would have to be a bug in our GSocketClient logic.
Either way, if such a bug were to exist, it would be better to surface
it rather than hide it.

These changes are actually going to be effectively undone in a
subsequent commit, as I'm refactoring the error handling, but the commit
history is a bit nicer with two separate commits, so let's go with two.
2020-10-09 10:50:22 -05:00
Michael Catanzaro
f0a7b14780 gsocketclient: emit RESOLVING/RESOLVED events only once
GSocketAddressEnumerator encapsulates the details of how DNS happens, so
we don't have to think about it. But we may have taken encapsulation a
bit too far, here. Usually, we resolve a domain name to a list of IPv4
and IPv6 addresses. Then we go through each address in the list and try
to connect to it. Name resolution happens exactly once, at the start.
It doesn't happen each time we enumerate the enumerator. In theory, it
*could*, because we've designed these APIs to be agnostic of underlying
implementation details like DNS and network protocols. But in practice,
we know that's not really what's happening. It's weird to say that we
are RESOLVING what we know to be the same name multiple times. Behind
the scenes, we're not doing that.

This also fixes #1994, where enumeration can end with a RESOLVING event,
even though this is supposed to be the first event rather than the last.
I thought this would be hard to fix, even requiring new public API in
GSocketAddressEnumerator to peek ahead to see if the next enumeration is
going to return NULL. Then I decided we should just fake it: always emit
both RESOLVING and RESOLVED at the same time right after each
enumeration. Finally, I realized we can emit them at the correct time if
we simply assume resolving only happens the first time. This seems like
the most elegant of the possible solutions.

Now, this is a behavior change, and arguably an API break, but it should
align better with reasonable expectations of how GSocketClientEvent
ought to work. I don't expect it to break anything besides tests that
check which order GSocketClientEvent events are emitted in. (Currently,
libsoup has such tests, which will need to be updated.) Ideally we would
have GLib-level tests as well, but in a concession to pragmatism, it's a
lot easier to keep network tests in libsoup.
2020-10-09 10:50:22 -05:00
Michael Catanzaro
290d5722be gsocketclient: document Happy Eyeballs
This isn't an API guarantee, but it's a potentially-surprising
behavior difference between the sync and async functions that is good
to know about, especially because our sync and async functions are
normally identical.
2020-10-09 10:50:22 -05:00
Michael Catanzaro
d971ac7b21 gsocketclient: fix whitespace error 2020-10-09 10:50:22 -05:00
Michael Catanzaro
d24970b207 gsocketclient: fix docs typo 2020-10-09 10:50:22 -05:00
Philip Withnall
497ea1a420 Merge branch 'ip_bind_address_no_port' into 'master'
gsocketclient: set IP_BIND_ADDRESS_NO_PORT if binding to local address

See merge request GNOME/glib!1598
2020-10-09 15:44:33 +00:00
Cristian Rodríguez
35bb69bc47 gsocketclient: set IP_BIND_ADDRESS_NO_PORT if binding to local address
The linux kernel does not know that the socket will be used
for connect or listen and if you bind() to a local address it must
reserve a random port (if port == 0) at bind() time, making very easy
to exhaust the ~32k port range, setting IP_BIND_ADDRESS_NO_PORT tells
the kernel to choose random port at connect() time instead, when the
full 4-tuple is known.
2020-10-09 09:44:05 +01:00
Sebastian Dröge
6cf381ee75 Merge branch 'spawn-error-handling' into 'master'
gspawn: Handle error opening /dev/null

See merge request GNOME/glib!1681
2020-10-07 13:48:36 +00:00
Sebastian Dröge
5d97eb9094 Merge branch '2203-fstatat-macos' into 'master'
glocalfileinfo: Fix use of fstatat() on macOS < 10.10

Closes #2203

See merge request GNOME/glib!1684
2020-10-07 13:47:13 +00:00
Philip Withnall
f55b278cc0 Merge branch 'wip/smcv/issue2087' into 'master'
Make it easier to filter logging

Closes #2087

See merge request GNOME/glib!1580
2020-10-07 13:41:07 +00:00
Simon McVittie
b17b537a7d gmessages: Expose our default filtering as API
This allows programs that want to change how log messages are printed,
such as gnome-terminal (gnome-terminal#42) and Flatpak, to override
the log-writer or the legacy log-handler without having to reimplement
the G_MESSAGES_DEBUG filtering logic.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-07 14:04:08 +01:00
Simon McVittie
10b0ece9d8 gmessages: Add API to move info and debug messages to stderr
GLib code normally prints info and debug messages to stdout,
but that interferes with programs that are documented to produce
machine-readable output such as JSON or XML on stdout. In particular,
if such a program uses a GLib-based library, setting G_MESSAGES_DEBUG
will typically result in that library's debug messages going to the
program's stdout and corrupting the machine-readable output.

Unix programs can avoid this by using dup2() to move the original stdout
to another fd, then dup2() again to make the new stdout a copy of stderr,
but it's easier if we provide a way to not write debug messages to
stdout in the first place. Calling
g_log_writer_default_set_use_stderr (TRUE) results in behaviour
resembling Python's logging.basicConfig(), with all diagnostics going
to stderr.

Suggested by Allison Karlitskaya on glib#2087.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-07 14:03:50 +01:00
Philip Withnall
97956c2d3d Merge branch 'boxing_gtree_gqueue_gnode' into 'master'
Add boxing for GTree, GQueue and GNode

Closes #1233

See merge request GNOME/glib!1029
2020-10-07 10:19:29 +00:00
Andrew Potter
3dc62171eb Add boxing for GTree
Closes issue #1233
2020-10-07 11:00:11 +01:00
Philip Withnall
7bfd6278b9 Merge branch 'gtree-add-iterators' into 'master'
GTree: add an ability to iterate over a tree and a node-based API

See merge request GNOME/glib!1509
2020-10-06 13:43:18 +00:00
Philip Withnall
1538a89b11 Merge branch 'close_subprocess_parent_fds_on_dispose' into 'master'
GSubprocessLauncher: Move cleanup to dispose()

See merge request GNOME/glib!1670
2020-10-06 11:41:35 +00:00
Philip Withnall
78e1431816 Merge branch 'log-fatal' into 'master'
gmessages: Document that using a custom log writer basically disables fatal handling

See merge request GNOME/glib!1678
2020-10-06 10:23:24 +00:00
Maciej S. Szmigiero
6569529e18 GLib test: test GTree "lower bound" and "upper bound" operations
"lower bound" and "upper bound" operations have been recently added to
GTree.
Let's add some tests for them where other GTree tests live.

Since adding keys in-order doesn't exercise the GTree insertion code very
well let's make sure they are inserted in a random order instead.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
2020-10-06 11:07:11 +01:00
Maciej S. Szmigiero
2e7931c760 GTree: add an ability to iterate over a tree and a node-based API
The basic API that this commit adds allows in-order iterating over a GTree.

For this the following API were implemented or exported:
1) Returning the first or the last node in the tree,

2) Taking a pointer to a node in the tree and returning the previous or the
next in-order node,

3) Allowing to do a binary search for a particular key value and returning
the pointer to its node,

4) Returning the newly inserted or set node from both insert and replace
functions, so this node is immediately available and does not have to be
looked up,

5) Traversing the tree in-order providing a node pointer to the
caller-provided traversal function.

Most of the above functions were already present in the code, but they
returned the value that is stored at a particular node instead of the
pointer to the node itself.

So most of the code for these new API calls is shared with these existing
ones, just adapted to return the pointer to the node.

Additionally, the so called "lower bound" and "upper bound" operations
were implemented.

The first one returns the first element that is greater than or equal to
the searched key, while the second returns the first element that is
strictly greater than the searched key.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
2020-10-06 11:07:11 +01:00