Commit Graph

17830 Commits

Author SHA1 Message Date
Philip Withnall
8e74fbf300 gnetworkaddress: Fix minor memory leak
From commit 99b792fac0.

Spotted by Coverity; CID 1385719.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-02-04 17:33:16 +01:00
Patrick Griffis
1c0bed93a3 docs: Clarify dest requirements of g_utf8_strncpy()
(Minor wording tweak by Philip Withnall.)

https://bugzilla.gnome.org/show_bug.cgi?id=520116
2018-02-03 12:12:28 +01:00
Philip Withnall
40be86bb0e gio: Port GThreadedResolver to use res_nquery() to fix thread-safety
res_query() uses global state in the form of the struct __res_state
which contains the contents of resolv.conf (and other things). On Linux,
this state seems to be thread-local, so there is no problem. On OS X,
however, it is not, and hence multiple res_query() calls from parallel
threads will compete and return bogus results.

The fix for this is to use res_nquery(), introduced in BIND 8.2, which
takes an explicit state argument. This allows us to manually store the
state thread-locally. If res_nquery() isn’t available, we fall back to
res_query(). It should be available on OS X though. As a data point,
it’s available on Fedora 27.

There’s a slight complication in the fact that OS X requires the state
to be freed using res_ndestroy() rather than res_nclose(). Linux uses
res_nclose().

(See, for example, the NetBSD man page:
https://www.unix.com/man-page/netbsd/3/res_ninit/. The Linux one is
incomplete and not so useful:
http://man7.org/linux/man-pages/man3/resolver.3.html.)

The new code will call res_ninit() once per res_nquery() task. This is
not optimal, but no worse than before — since res_query() was being
called in a worker thread, on Linux, it would implicitly initialise the
thread-local struct __res_state when it was called. We’ve essentially
just made that explicit. In practical terms, this means a
stat("/etc/resolv.conf") call per res_nquery() task.

In future, we could improve this by using an explicit thread pool with
some manually-created worker threads, each of which initialises a struct
__res_state on spawning, and only updates it on receiving
the #GResolver::reload signal.

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

https://bugzilla.gnome.org/show_bug.cgi?id=792050
2018-02-02 18:05:27 +01:00
Allison Lortie
235f4958a9 gsettings: remove redundancy in 'list-recursive'
Some projects use child schemas in an odd way: they link children which
already have their path pre-defined.  This causes the child schema (and
its keys) to be printed out twice:

 - once because it is, itself, a non-relocatable schema

 - once, as a recursion from its parent

We can avoid this by not recursing into child schemas that are
non-relocatable (on the assumption that they will be enumerated
elsewhere).

https://bugzilla.gnome.org/show_bug.cgi?id=723003
2018-02-02 14:41:00 +01:00
Philip Withnall
32cc60dbff gmessages: Fix -Wformat warnings for g_message() and friends
When compiling with G_LOG_USE_STRUCTURED, g_message(), g_debug(), etc.
use g_log_structured(). The message format string and its format
arguments are passed as the final set of arguments in a longer varargs
list, which includes the log domain and level (and other) fields.
Passing the message format in this way means it’s not possible for the
compiler to know to check its format placeholders when compiling with
-Wformat.

Fix support for this by adding a new semi-private helper function,
_g_log_structured_standard(), which only uses varargs for the message
format and its arguments, and uses fixed arguments for the other fields.
This is then converted to a set of GLogFields and passed to
g_log_structured() as normal.

Support for -Wformat when compiling *without* G_LOG_USE_STRUCTURED was
never broken.

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

https://bugzilla.gnome.org/show_bug.cgi?id=793074
2018-02-02 10:10:43 +01:00
Philip Withnall
07f75f6cc2 gdbusmessage: Make a translatable message translatable with plurals
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=658713
2018-02-02 10:07:12 +01:00
Philip Withnall
5ed77c1104 gdatainputstream: Deprecate read_until() in favour of read_upto()
g_data_input_stream_read_upto() was introduced in 2.26; now it’s GLib
2.56, we can probably deprecate the old versions (since the handling of
consuming the stop character differs between the sync and async versions
of it).

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

https://bugzilla.gnome.org/show_bug.cgi?id=584284
2018-02-02 10:05:55 +01:00
Philip Withnall
3a88ab6c25 tests: Add some documentation to the illegal sequence conversion test
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
8abf3a04e6 gconvert: Fix error handling for g_iconv() with unrepresentable chars
The behaviour of upstream iconv() when faced with a character which is
valid in the input encoding, but not representable in the output
encoding, is implementation defined:

http://pubs.opengroup.org/onlinepubs/9699919799/

Specifically:

   If iconv() encounters a character in the input buffer that is valid,
   but for which an identical character does not exist in the target
   codeset, iconv() shall perform an implementation-defined conversion
   on this character.

This behaviour was being exposed in our g_iconv() wrapper and also in
g_convert_with_iconv() — but users of g_convert_with_iconv() (both the
GLib unit tests, and the implementation of g_convert_with_fallback())
were assuming that iconv() would return EILSEQ if faced with an
unrepresentable character.

On platforms like NetBSD, this is not the case: NetBSD’s iconv()
finishes the conversion successfully, and outputs a string containing
replacement characters. It signals those replacements in its return
value from iconv(), which is positive (specifically, non-zero) in such a
case.

Let’s codify the existing assumed behaviour of g_convert_with_iconv(),
documenting that it will return G_CONVERT_ERROR_INVALID_SEQUENCE if
faced with an unrepresentable character. As g_iconv() is a thin wrapper
around iconv(), leave the behaviour there implementation-defined (but
document it as such).

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
a19eed4691 tests: Add a missing const to a variable in the GConvert tests
Also rename it to make it clearer how it’s encoded (as UTF-8).

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
19bc03ef65 docs: Minor wording improvements in GConvert documentation
Fix capitalisation of GLib, make some text less gender-specific, and add
some missing colons.

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
ad6afd0fc1 docs: Replace an XML entity with a UTF-8 character instead
Another part of the long tail of converting our documentation from
DocBook to Markdown.

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
38592939d7 docs: Clarify the definition of goffset
off64_t doesn’t exist in any standard (definitely not C99), and so
goffset is actually closer to off_t in 64-bit mode.

However, goffset is always defined as gint64, so make that clear.

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

https://bugzilla.gnome.org/show_bug.cgi?id=792856
2018-02-02 09:29:22 +01:00
Stewart Brodie
fc857073a0 gkeyfile: Fix FD validity test to be technically correct
The fd could be valid and zero.

https://bugzilla.gnome.org/show_bug.cgi?id=760324
2018-02-02 09:20:11 +01:00
Philip Withnall
b6d1c128b3 gcharset: Mention the environment variables queried by g_get_charset()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-01 17:38:28 +00:00
Bastien Nocera
e889fb2a7f resolver: Return early if URI is invalid
https://bugzilla.gnome.org/show_bug.cgi?id=772989
2018-02-01 14:58:29 +00:00
Bastien Nocera
99b792fac0 networkaddress: Add early sanity check to _g_uri_parse_authority()
Check whether the URI is valid ASCII before trying to parse it. This
should catch broken URIs early.

https://bugzilla.gnome.org/show_bug.cgi?id=772989
2018-02-01 14:58:28 +00:00
Bastien Nocera
5f2c20e88b networkaddress: Return an error from _g_uri_parse_authority()
So that errors can be propagated if necessary.

https://bugzilla.gnome.org/show_bug.cgi?id=772989
2018-02-01 14:58:28 +00:00
Bastien Nocera
88366621ee GSimpleProxyResolver: Add test case for broken hostname
https://bugzilla.gnome.org/show_bug.cgi?id=772989
2018-02-01 14:58:28 +00:00
Bastien Nocera
132cf9a9d4 resolver: Return error looking up services on invalid hostnames
Make g_resolver_lookup_service() and
g_resolver_lookup_service_async() error out when invalid hostnames are
passed.

https://bugzilla.gnome.org/show_bug.cgi?id=772989
2018-02-01 14:58:28 +00:00
Bastien Nocera
cb8c919952 simpleproxyresolver: Don't crash on invalid hostname
Check for g_hostname_to_ascii() failure, rather than crashing when
checking whether an invalid hostname should go through the proxy.

The HTTP library should report the error about the invalid hostname
once we actually try to connect to it.

https://bugzilla.gnome.org/show_bug.cgi?id=772989
2018-02-01 14:17:50 +00:00
Ignacio Casal Quinteiro
1a99154898 gpollableoutputstream: document side effects of WOULD_BLOCK on D/TLS
If the underlying transport is D/TLS the same data and data length
is required to be sent on the next iteration when a WOULD_BLOCK
happens. This is due to the fact that gnutls or openssl keep
an internal state for the data.

https://bugzilla.gnome.org/show_bug.cgi?id=792862
2018-01-31 22:37:18 +00:00
Philip Withnall
4752d72a60 gdbusaddress: Disable proxy support for D-Bus addresses
See the discussion in the bug report: with proxy support enabled, a
proxy resolver is created. Doing that will load all the GIO modules, and
typically at least one of them will try to use GDBus during
initialisation, which will cause a deadlock.

Using a TCP address with GDBusAddress is still supported, but accessing
it over a proxy is not.

Document this.

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

https://bugzilla.gnome.org/show_bug.cgi?id=792499
2018-01-31 22:25:02 +00:00
Iñigo Martínez
3ef83618d9 gdbus-codegen: Improve documentation
Recent changes has extended the functionality of `gdbus-codegen`
by implementing new options.

This patch extends the documentation including the behaviour of
the new options along the old ones.

(Wording tweaked by Philip Withnall before pushing.)

https://bugzilla.gnome.org/show_bug.cgi?id=791015
2018-01-31 22:14:04 +00:00
Iñigo Martínez
93042e0052 gdbus-codegen: Fix issue with docbook generation
In cases where gdbus-codegen is used only for docbook generation,
the execution stops with the following error message:

  `Using --header or --body requires --output`

This is because it was assumed that, in addition to the docbook
generation, the header or source code were always generated.

This patch fixes this, and the header or source code generation
is not mandatory, so the docbook can be generated separately.

https://bugzilla.gnome.org/show_bug.cgi?id=791015
2018-01-31 22:12:51 +00:00
Pavlo Solntsev
382d13b618 Clarification for memmory allocation function
Difference between g_try_... family of functions and their counterparts
has been clarified.

https://bugzilla.gnome.org/show_bug.cgi?id=792903
2018-01-31 22:10:51 +00:00
Ondrej Holy
7e0d42e3dc gunixmounts: Skip accumulated events from file monitor
Skip accumulated events from file monitor which we are not able to handle
in a real time instead of emitting mounts_changed signal several times.
This should behave equally to GIOChannel based monitoring. See Bug 792235.

https://bugzilla.gnome.org/show_bug.cgi?id=793006
2018-01-30 15:31:13 +01:00
Emmanuele Bassi
c1d58dd7e0 build: Document the chmod-scripts configure command
The chmod of all the scripts we generate from a template via configure
is necessary because configure will not preserve the bits of the
template when generating a new file.

There's no explanation for it, and you have to hunt it down the commit
history. Since Meson does the right thing, we added the executable bit
on the templates, but we cannot remove the AC_CONFIG_COMMANDS macro from
the Autotools build without breaking it. Let's document this, to avoid
nasty surprises.
2018-01-30 11:18:34 +00:00
Christian Hergert
47b78e6d83 tests: additional test for g_bytes_new_from_bytes()
This adds two new tests for g_bytes_new_from_bytes().

One test ensures that when creating a new GBytes that is a slice of
the entire base bytes, we just return the base bytes with it's reference
count incremented by one.

The other test ensures that when performing sub-slices of GBytes, for
which the parent GBytes also references a GBytes, that we skip the
intermediate GBytes and reference the base GBytes. Additional testing
of the internal state of the GBytes structure is performed to prove
the correctness of the implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=792780
2018-01-27 11:43:38 -08:00
Christian Hergert
4151bce6db bytes: avoid intermediate refs in g_bytes_new_from_bytes()
When referencing a GBytes that is already a slice of another GBytes, we
can avoid referencing the intermediate GBytes and instead reference the
root bytes.

Doing so helps avoid keeping N GBytes instances alive when the
intermediates would have otherwise been finalized.

https://bugzilla.gnome.org/show_bug.cgi?id=792780
2018-01-27 11:43:38 -08:00
Bastien Nocera
801accf746 GNotification: Don't ignore set_urgent()'s argument
set_urgent() would behave is if @urgent was always true. The regression
was introduced in commit 01098e34c1

https://bugzilla.gnome.org/show_bug.cgi?id=792777
2018-01-23 14:24:12 +00:00
Philip Withnall
cea72036e3 gnotification: Add missing deprecation tag to set_urgent()
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=792777
2018-01-22 11:24:47 +00:00
Balázs Úr
66824159cd Update Hungarian translation 2018-01-21 21:27:00 +00:00
Mikhail Zabaluev
52f98911df Test that g_convert() can handle embedded NUL bytes
https://bugzilla.gnome.org/show_bug.cgi?id=792516
2018-01-19 11:46:31 +00:00
Mikhail Zabaluev
f35a6a7031 gconvert: Consistently validate inputs and outputs for embedded NULs
String inputs to convenience conversion functions g_locale_from_utf8(),
g_filename_from_utf8(), and g_filename_to_utf8(), are annotated for the
bindings as NUL-terminated strings of (type utf8) or (type filename).
There is also a len parameter that allows converting part of the string,
but it is exposed to the bindings as a value independent from the string
buffer. Absent any more sophisticated ways to annotate, the way to
provide a safeguard against len argument values longer than the
string length is to check that no nul is encountered within the first
len bytes of the string. strdup_len() includes this check as part of
UTF-8 validation, but g_convert() permits embedded nuls.

For g_filename_from_utf8(), also check the output to prevent embedded NUL
bytes. It's not safe to allow embedded NULs in a string that is going
to be used as (type filename), and no known bytestring encoding for
file names allows them.

https://bugzilla.gnome.org/show_bug.cgi?id=792516
2018-01-19 11:46:31 +00:00
Mikhail Zabaluev
d584ff77f6 Test embedded NULs in input of g_{locale,filename}_to_utf8()
The tests exercise both g_strncpy() and g_convert() paths.

https://bugzilla.gnome.org/show_bug.cgi?id=792516
2018-01-19 11:46:31 +00:00
Mikhail Zabaluev
81cd815406 gconvert: Tighten, document embedded NUL behavior of UTF-8 conversions
The character encoding conversion utility functions g_locale_to_utf8()
and g_filename_to_utf8() had inconsistent behavior on producing strings
with inner NUL bytes: in the all-UTF-8 strdup path, the input string
validation prohibits embedded NULs, while g_convert(), using iconv(),
can produce UTF-8 output with NUL bytes inside the output buffer.
This, while valid UTF-8 per the Unicode standard, is not valid for
the nul-terminated (type utf8) return value format that the *_to_utf8()
functions are annotated with (as per discussion in bug 756128).

Check the output of g_convert() for embedded NUL bytes, and if any
are found, set the newly introduced error
G_CONVERT_ERROR_EMBEDDED_NUL.

Also document the error set by g_{locale,filename}_{from,to}_utf8()
when the input string contains nul bytes.

https://bugzilla.gnome.org/show_bug.cgi?id=792516
2018-01-19 11:46:31 +00:00
Mikhail Zabaluev
413605a6f3 gconvert: Optimize UTF-8 conversions, fix output on error
In the strdup_len() path, no need to do what g_utf8_validate()
already does: locate the string-terminating nul byte.

Also in strdup_len(), make the out parameter bytes_read receive the length
of the valid (meaning also nul-free) part of the input string, as the
documentation on g_{locale,filename}_{from,to}_utf8() says it does.

https://bugzilla.gnome.org/show_bug.cgi?id=792516
2018-01-19 11:46:31 +00:00
Philip Withnall
1e6803be3b gmain: Partial revert of recent wakeup changes to gmain.c
This reverts the following commits (but keeps the other recent changes
to gmain.c):
 • e4ee3079c Do not wake up main loop if change is from same thread
 • 208702404 main: Create a helper function for "owner wakeup" optimization
 • 0c0469b56 gmain: Signal wakeups if context has never been acquired as well
 • 9ba95e25b gmain: only signal GWakeup right before or during a blocking poll

Some combination of them is causing problems with LibreOffice and/or
WebKit, and the safest thing to do at the moment is revert them all
until we work out what’s going on. The previous revert (4976e8109) was
not sufficient (it fixed WebKit, but re-broken LibreOffice).

By reverting, we gain some spurious wakeups, but avoid dropping
necessary wakeups, which is presumably what’s causing problems in the
other modules.

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

https://bugzilla.gnome.org/show_bug.cgi?id=761102
2018-01-18 11:31:08 +00:00
Philip Withnall
3787e42932 gio: Rename GNetworkMonitorWindows to GWin32NetworkMonitor
This makes it more consistent with other GWin32* objects. No functional
changes.

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

https://bugzilla.gnome.org/show_bug.cgi?id=685442
2018-01-18 10:12:26 +00:00
Philip Withnall
ba976f13b6 gio: Rename gnetworkmonitorwindows to gwin32networkmonitor
This makes it more consistent with the other win32 objects in GIO. This
commit just renames the files; a follow-up commit will rename the
GObject.

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

https://bugzilla.gnome.org/show_bug.cgi?id=685442
2018-01-17 12:59:51 +00:00
Jan-Michael Brummer
f9aacf3952 GNetworkMonitorWindows: Add IPv4/IPv6 network monitor backend for windows
Added a Windows backend to GNetworkMonitor, using NotifyRouteChange2()
(available on Vista and later). It marshals the route change callbacks
to the thread-specific default main context the GNetworkMonitor was
constructed in.

https://bugzilla.gnome.org/show_bug.cgi?id=685442
2018-01-17 12:31:26 +00:00
Sébastien Wilmet
3ee859d5fc docs: GSequence: better document how to sort large amount of data
It was documented at strange places: in g_sequence_search*() and
g_sequence_lookup*(), but how to insert and sort data is not done by
those functions.

So instead, add the information to the class description (since it
involves several functions), and add also the information in
g_sequence_insert_sorted() and g_sequence_insert_sorted_iter() as a kind
of warning when using those functions.

Note that before this commit, it was not explained *why* it is better to
call g_sequence_sort() after doing a lot of unsorted insertions. Now it
is documented as "more efficient" (I think it's the only reason that
makes sense, otherwise why was it documented?).

https://bugzilla.gnome.org/show_bug.cgi?id=792455
2018-01-16 20:11:31 +01:00
Emmanuele Bassi
c685ce973d Fix dir separator in the Autotools build on Windows
Just like we fixed the Meson build in commit f25c7a2a, we need to escape
twice: once for the shell expansion, and the other for the C string
constant.
2018-01-16 15:19:41 +00:00
Emmanuele Bassi
dcfa22549a docs: Small improvements to glib-mkenums man page
Clarify some typical usage of glib-mkenums and its substitutions.
2018-01-16 15:17:54 +00:00
Emmanuele Bassi
e6c3060144 docs: Drop references to Perl in glib-mkenums
The tool was ported to Python, but we should not mention the programming
language used, in case we port it to some other language in the distant
future.
2018-01-16 15:17:53 +00:00
Benjamin Berg
5fba62adec gmessages: Flush output stream after logging messages
When debug output is enabled then certain messages will be logged to
stdout. stdout however is block buffered by default when it isn't going
to a TTY meaning that debug logging will not be flushed out properly
when it is being redirected. One example of this happening may be tests
that rely on parsing g_debug messages.

Adding an explicit fflush ensures all log messages will reach the output.

https://bugzilla.gnome.org/show_bug.cgi?id=792432
2018-01-15 19:46:22 +01:00
Philip Withnall
051d69bbc8 gdataset: Fix a typo in a documentation comment
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-01-15 18:26:56 +00:00
Colin Walters
4808a957b5 GFile: Add g_file_peek_path()
This is a variant of g_file_get_path() which returns a const string to
the caller, rather than transferring ownership.

I've been carrying `gs_file_get_path_cached()` in libgsystem and it
has seen a lot of use in the ostree and flatpak codebases.  There are
probably others too.

I think language bindings like Python/Gjs could also use this to avoid
an extra malloc (i.e. we could transparently replace
`g_file_get_path()` with `g_file_peek_path()`.

(Originally by Colin Walters. Tweaked by Philip Withnall to update to
2.56, change the function name and drop the locking.)

https://bugzilla.gnome.org/show_bug.cgi?id=767976
2018-01-15 18:26:56 +00:00
Iñigo Martínez
261cb8ea86 gdbus-codegen: Set source coding to utf-8
Some of the recent changes introduced UTF-8 characters which made
gdbus-codegen to crash when using Python 2.

Following PEP 263, the utf-8 coding comment has been used.

PEP: https://www.python.org/dev/peps/pep-0263/
BUG: https://bugzilla.gnome.org/show_bug.cgi?id=791015

Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
2018-01-15 17:04:31 +01:00