Commit Graph

6066 Commits

Author SHA1 Message Date
Philip Withnall
aee897bd89 gutils: Fix a typo in a comment
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/538
2018-12-17 17:16:03 +00:00
Philip Withnall
f27532e784 gtestutils: Move a documentation comment to the symbol it documents
Seems a bit odd to have the documentation comment miles from what it’s
actually documenting.

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

https://gitlab.gnome.org/GNOME/glib/issues/538
2018-12-17 17:16:03 +00:00
Philip Withnall
00b50d28f9 gutils: Fix a typo in a documentation comment
‘threadsafety’ isn’t a word.

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

https://gitlab.gnome.org/GNOME/glib/issues/538
2018-12-17 17:16:03 +00:00
Philip Withnall
e6eb4869ba gutils: Refactor initialisation of XDG variables
Split out the code which calculates each XDG variable value from the
code which caches it, so that GLib can internally recalculate the
variables if needed, without necessarily trashing the user-visible
cache.

This will be useful in a following commit to add support for explicitly
reloading the variables.

This commit necessarily reworks how g_get_user_runtime_dir() is
structured, since it was inexplicably structured differently from (but
equivalently to) the other XDG variable functions.

Future refactoring could easily share a lot more code between these
g_build_*() functions.

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

https://gitlab.gnome.org/GNOME/glib/issues/538
2018-12-17 17:16:03 +00:00
Philip Withnall
a67eadbdc3 gstrfuncs: Add g_strv_equal()
This is a utility function which I find myself writing in a number of
places. Mostly in unit tests.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-17 17:16:03 +00:00
Philip Withnall
903ce7dc02 Merge branch '1191-g_assert_cmpvariant' into 'master'
gtestutils: Add g_assert_cmpvariant()

Closes #1191

See merge request GNOME/glib!529
2018-12-17 13:03:00 +00:00
Mart Raudsepp
2ceb48dfc2 gtimezone: Fallback to /etc/timezone on Gentoo
On non-systemd Gentoo systems the chosen timezone is expressed in
/etc/timezone and /etc/localtime may be a copy of the timezone
file instead of symlink. Add this path to the fallback test to
not regress dates into UTC.
2018-12-17 00:42:39 +02:00
Philip Withnall
d289ef449b tests: Port various tests to use g_assert_cmpvariant()
This should improve test error reporting a little.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-14 15:04:11 +00:00
Philip Withnall
8a2fa212e7 docs: Format operators nicely in gtestutils documentation
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-12 11:27:32 +00:00
Philip Withnall
ee364db967 gtestutils: Add g_assert_cmpvariant()
This is along the same lines as g_assert_cmpstr(), but for variants.

Based on a patch by Guillaume Desmottes.

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

https://gitlab.gnome.org/GNOME/glib/issues/1191
2018-12-12 11:27:25 +00:00
Xavier Claessens
3fadcf9ffa Merge branch 'meson-pkgconfig' into 'master'
Meson: Fix deprecation warning with upcoming 0.49.0 release

See merge request GNOME/glib!517
2018-12-10 20:19:38 +00:00
Tomasz Miąsko
db47ab8402 gdatetime: Fix typo in the comment
Follow up on https://gitlab.gnome.org/GNOME/glib/merge_requests/506#note_382186.
2018-12-10 17:54:27 +01:00
Xavier Claessens
475f0a9b67 Meson: Fix deprecation warning with 0.49.0 release
http://mesonbuild.com/Release-notes-for-0-49-0.html#deprecation-warning-in-pkgconfig-generator
2018-12-10 09:08:28 -05:00
Philip Withnall
b1f16259fc Merge branch 'issue-1605' into 'master'
gdatetime: Store intermediate result of g_date_time_format in UTF-8

Closes #1605

See merge request GNOME/glib!506
2018-12-10 12:03:17 +00:00
Tomasz Miąsko
e32342897a tests: Rename macro to avoid conflict with encoding prefix
Use macro name that doesn't conflict with string literal encoding prefix `U`.

```
../glib/tests/fileutils.c(282): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *'
../glib/tests/fileutils.c(284): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *'
../glib/tests/fileutils.c(285): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *'
../glib/tests/fileutils.c(286): warning C4133: 'function': incompatible types - from 'unsigned int [2]' to 'const gchar *'
../glib/tests/fileutils.c(287): warning C4133: 'function': incompatible types - from 'unsigned int [3]' to 'const gchar *'
...
```
2018-12-09 15:10:43 +01:00
Philip Withnall
d2224b475d gvariant: Fix error handling for parsing Unicode escapes
When parsing an escaped Unicode character in a text format GVariant
string, such as '\U0001F415', the code uses g_ascii_strtoull(). This,
unexpectedly, accepts minus signs, which can cause an assertion failure
when input like '\u-FF4' is presented for parsing.

Validate that there are no leading sign characters when parsing.

This shouldn’t be considered a security bug, because the GVariant text
format parser should not be used on untrusted input.

oss-fuzz#11576

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-04 12:55:21 +00:00
Philip Withnall
ca328615c8 gvariant: Use gsize rather than gint for array lengths
This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-04 12:54:39 +00:00
Philip Withnall
96acb49eb1 gstrfuncs: Clarify that g_ascii_string_to_unsigned() rejects signs
Unlike g_ascii_strtoull(), g_ascii_string_to_unsigned() does not permit
leading signs (`+` or `-`). Document that.

It’s already in the unit tests.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-04 12:53:52 +00:00
Philip Withnall
8d0a163000 gstrfuncs: Clarify that g_ascii_strtoull() accepts signed numbers
It’s perverse, but explicitly documented that strtoull() accepts numbers
with a leading minus sign (`-`) and explicitly casts them to signed
output.

g_ascii_strtoull() is documented to do what strtoull() does (but locale
independently), and its behaviour is correct. However, the documentation
could be a lot clearer about this unexpected behaviour.

Add a unit test for it too.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-04 12:51:09 +00:00
Tomasz Miąsko
8bfa45817e gdatetime: Avoid unnecessary conversions from ASCII to UTF-8 2018-12-04 13:34:33 +01:00
Tomasz Miąsko
bc59892b1a gdatetime: Store intermediate result of g_date_time_format in UTF-8
In date time formatting routine, instead of converting from UTF-8 to
locale charset and then from locale charset to UTF-8, store all
intermediate result in UTF-8.

This solves the issue where user provided UTF-8 format string might be
unrepresentable in the current locale charset.

Fixes issue #1605.
2018-12-04 13:34:18 +01:00
Tomasz Miąsko
69fbf3ed59 tests: Unset LANGUAGE when running gdatetime tests
In glibc, LANGUAGE is used as highest priority guess for category value.
Unset it to avoid interference with tests using setlocale and translation.

Issue #1357.
2018-11-29 23:35:54 +01:00
Peter Wu
a51ab0a5ab genviron: make g_environ_* case-insensitive on Windows
g_environ_getenv(env, "PATH") and g_environ_setenv(env, "PATH", newpath)
did not have the intended effect on Windows due to the environment block
containing "Path=". Make these functions case-insensitive for Windows.
2018-11-28 11:04:48 +01:00
Will Thompson
4544dcb788
gmain: test far-future ready_time 2018-11-27 10:40:35 +00:00
Will Thompson
cdc2dd8eb1
gmain: clamp over-large timeouts
g_main_context_prepare() needs to calculate the timeout to pass to
poll(), expressed in milliseconds as a gint.  But since the ready time
for a GSource is represented by gint64 microseconds, it's possible that
it could be more than G_MAXINT * 1000 microseconds in the future, and so
can't be represented as a gint. This conversion to a narrower signed
type is implementation-defined, but there are two possible outcomes:

* the result is >= 0, in which case poll() will time out earlier than we
  might hope (with no adverse consequences besides an unwanted wakeup)
* the result is < 0, in which case, if there are no other sources,
  poll() will block forever

This is extremely unlikely to happen in practice, but can be avoided by
clamping the gint64 value, which we know to be positive, to G_MAXINT.

Thanks to Tomasz Miąsko for pointing this out on !496.
2018-11-27 10:36:20 +00:00
Will Thompson
6490fe7fe8
g_timeout_*_seconds: test an interval that overflowed
This is essentially a C version of the reproducer on #1600. It is based
on the existing test_seconds(), which relates to a similar but distinct
overflow.

I've only actually run this on a system with 32-bit ints, it should work
regardless of the width of an int, since the remainder after wrapping
will by construction be less than 1 second.
2018-11-27 10:36:20 +00:00
Will Thompson
4ff3734ff5
g_timeout_*_seconds: don't overflow for large intervals
Previously, the `guint interval` parameter, measured in seconds, was
multiplied by 1000 and stored in another `guint` field. For intervals
greater than (G_MAXUINT / 1000) seconds, this would overflow; the
timeout would fire much sooner than intended.

Since GTimeoutSource already keeps track of whether it was created at
millisecond or second resolution, always store the passed interval
directly. We later convert the interval to microseconds, stored in a
gint64, so can move the `* 1000` to there.

The eagle-eyed reader might notice that there is no obvious guarantee
that the source's expiration time in microseconds won't overflow the
gint64, but I don't think this is a new problem. Previously, the
monotonic time would have to reach (2 ** 63 - 2 ** 32) microseconds for
this overflow to occur; now it would have to reach approximately (2 **
63 - 2 ** 42) microseconds. Both of these are 292.47 millennia to 5
significant figures.

Fixes #1600.
2018-11-26 16:04:10 +00:00
Emmanuele Bassi
4326d5e27d Merge branch '1498-distcheck' into 'master'
Various distcheck and docs fixes

Closes #1498

See merge request GNOME/glib!488
2018-11-26 11:49:36 +00:00
Philip Withnall
8c9c9d92cc Merge branch '1014-gspawn-linux-threadsafety' into 'master'
gspawn: Fix g_spawn deadlock in a multi-threaded program on Linux

Closes #1014 and #945

See merge request GNOME/glib!490
2018-11-26 10:48:52 +00:00
Emmanuele Bassi
8316ae2241 Merge branch 'non-atomic-init' into 'master'
gatomicrefcount: Make g_atomic_ref_count_init non-atomic

See merge request GNOME/glib!460
2018-11-25 00:52:56 +00:00
Peter Wu
f2917459f7 gspawn: Fix g_spawn deadlock in a multi-threaded program on Linux
opendir and closedir are not async-signal-safe, these may call malloc
under the hood and cause a deadlock in a multi-threaded program.
This only affected Linux when /proc is mounted, other systems use a
slower path that iterates through all potential file descriptors.
Fixes a long-standing problem (since GLib 2.14.2).

Closes #945 and #1014
2018-11-24 16:01:28 +01:00
Philip Withnall
2722e9b31b build: Add a missing file to CLEANFILES
No idea why this didn’t cause problems with distcheck before.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-23 17:17:39 +00:00
Philip Withnall
1a46bf88bb docs: Add missing documentation for warnings and assertions
These symbols were listed in glib-undocumented.txt. Thanks gtk-doc.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-23 12:19:19 +00:00
Tomasz Miąsko
c2b22bd615 gthread: Synchronize access to g_once_init_list 2018-11-19 19:41:50 +01:00
Marco Trevisan (Treviño)
86c073dba9 gmacros: remove duplication on autoptr cleanup definition
Define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS and reuse it for both
_GLIB_DEFINE_AUTOPTR_CHAINUP and G_DEFINE_AUTOPTR_CLEANUP_FUNC
2018-11-14 22:47:39 -06:00
Marco Trevisan (Treviño)
d58be1bda9 gmacros: make _GLIB_DEFINE_AUTOPTR_CHAINUP to define funcs for g_autolist
Also chainup to glib_(s)listautoptr_cleanup_* parent functions
to make g_autolist work with object defined in this way
2018-11-14 14:41:40 -06:00
Philip Withnall
6375476743 Merge branch 'gmain-tsan' into 'master'
gmain: Fix data races in GUnixSignalWatchSource and GChildWatchSource

See merge request GNOME/glib!446
2018-11-13 16:04:12 +00:00
Tomasz Miąsko
dd36cf3a8b gmain: Indicate atomic fields with a comment 2018-11-13 14:57:45 +01:00
Tomasz Miąsko
969b0e00b3 gmain: Guarantee handler dispatch after receiving UNIX signal
Guarantee that user signal callback is dispatched _after_ receiving a
signal as long as the handler expresses continued interest in receiving
such a notification.

Previously if a signal has been received during user callback dispatch
but before pending flag had been cleared then the signal would be
irrevocably lost.

This is a very useful guarantee to have in cases where signals are used
to signify a need for synchronization with external resources. For
example: reloading configuration file after SIGUSR1 or retrieving a
terminal size after SIGWINCH.
2018-11-13 14:57:27 +01:00
Tomasz Miąsko
9e652f94d2 gmain: Make GUnixSignalWatchSource pending field atomic
Ensure synchronization between prepare / check /dispatch of
GUnixSignalWatchSource and UNIX signal dispatcher by making operations
on `pending` field atomic.

Issue #1312.
2018-11-13 14:57:22 +01:00
Tomasz Miąsko
d2fd53df03 gmain: Make GChildWatchSource child_exited field atomic
Ensure synchronization between prepare / check of GChildWatchsource and
UNIX signal dispatcher by making operations on `child_exited` field
atomic. Use `child_exited` as publication flag for `child_status`.

Issue #1312.
2018-11-13 14:52:50 +01:00
Tomasz Miąsko
1c8f3c67c3 gmain: Remove redundant volatile from unix_signal_refcount
Acesss to unix_signal_refcount is protected by unix_signal_lock.
2018-11-13 14:52:50 +01:00
Tomasz Miąsko
ba18822f35 gdate: Use longest matching month name in g_date_set_parse
There are languages where a name of one month is a substring of another.
Instead of stopping search on the first match use the month that
constitutes the longest match.

Fixes #1343.
2018-11-13 14:43:34 +01:00
Philip Withnall
e0148985f3 Merge branch 'tests-tsan' into 'master'
tests: Fix some data races in tests

See merge request GNOME/glib!453
2018-11-13 13:12:38 +00:00
Philip Withnall
e990a9ff8e Merge branch '107-key-file-comment-line-breaks' into 'master'
gkeyfile: Fix parsing of new lines in comments

Closes #107

See merge request GNOME/glib!432
2018-11-12 12:57:24 +00:00
Will Thompson
f1175704b6
gmessages: don't memoize in g_log_writer_is_journald()
Previously, g_log_writer_is_journald() would cache the result for the
first (non-negative) FD it was called on, and return that result for
all future (non-negative) FDs. While unlikely, it's possible that
applications might call this function on something other than
fileno(stderr).

Move the memoization into g_log_writer_default(), which always passes
fileno(stderr).

Fixes #1589.
2018-11-12 11:20:49 +00:00
Tomasz Miąsko
4fde2b273d gatomicrefcount: Make g_atomic_ref_count_init non-atomic
Programmer needs to ensure that initializations happens before other
operations on gatomicrefcount as otherwise they could access
uninitialized memory, so there is no practical use case for making
initialization atomic.
2018-11-08 16:04:51 +01:00
Philip Withnall
0c6346c98f Merge branch 'atomic-ref-count-cnd' into 'master'
Atomic reference count in GVariant, ContainerInfo and GDBus introspection

See merge request GNOME/glib!452
2018-11-08 14:22:03 +00:00
Philip Withnall
0ef8dde34e Merge branch '1342-gvariant-alignment' into 'master'
gvariant: Realign data on construction if it’s not properly aligned

Closes #1342

See merge request GNOME/glib!455
2018-11-07 16:55:50 +00:00
Tomasz Miąsko
b5a41afb18 gvarianttypeinfo: Use gatomicrefcount for ContainerInfo reference count 2018-11-06 14:44:25 +01:00