Commit Graph

6066 Commits

Author SHA1 Message Date
Emmanuele Bassi
3da4314205 Merge branch 'hash-table-tests' into 'master'
tests: Add more tests to finish branch coverage of GHashTable

See merge request GNOME/glib!289
2018-09-05 10:12:07 +00:00
Philip Withnall
98f326a020 Merge branch 'wip/otte/fallthrough' into 'master'
Add G_GNUC_FALLTHROUGH for __attribute__(fallthrough))

See merge request GNOME/glib!296
2018-09-04 22:06:26 +00:00
Benjamin Otte
3aff811d13 Use G_GNUC_FALLTHROUGH where appropriate 2018-09-04 20:24:25 +02:00
Benjamin Otte
95477a4e35 macros: Add G_GNUC_FALLTHROUGH
Expands to the GNU C fallthrough statement attribute if the compiler is gcc.
This allows declaring case statement to explicitly fall through in switch
statements. To enable this feature, use -Wimplicit-fallthrough during
compilation.
2018-09-04 20:24:21 +02:00
Iain Lane
68a4e273b4 Document that GTimeVal is subject to the year 2038 problem on 32-bit systems
It might not be immediately obvious that this is the case. Let's record
it in the description of `GTimeVal` itself and also in
`g_time_val_from_iso8601`.

We also drop an incorrect statement in the documentation for
`g_time_val_from_iso8601` stating that years up to 3000 were supported;
this is also not true for the same reason.

Related: #1509
2018-09-04 11:15:25 +01:00
Iain Lane
f697f6aa08 tests/timer: Skip test_timeval_to_iso8601_overflow if we can't overflow a GTimeVal
On 32 bit systems, the size of a long might be the same as the size of
an int. In that case, we won't be able to get an overflow when
converting from a GTimeVal to a time_t. Skip the test for this in that
case.

Closes #1509
2018-09-04 10:31:52 +01:00
Philip Withnall
d3656705fa Merge branch 'default-tls-database' into 'master'
gtlsbackend: add support for setting the default TLS database

Closes glib-networking#35

See merge request GNOME/glib!273
2018-09-03 13:22:39 +00:00
Philip Withnall
17ae9f36da Merge branch 'O_CLOEXEC' into 'master'
gspawn: Fix build on systems without O_CLOEXEC

See merge request GNOME/glib!286
2018-09-03 11:51:06 +00:00
Matthew Waters
6545e7558c gversionmacros: add version macros for GLib 2.60 2018-09-03 13:55:57 +10:00
Xavier Claessens
b2375471cc Merge branch '1313-config-cleanups' into 'master'
More config.h fixups for Meson

Closes #1313

See merge request GNOME/glib!283
2018-08-31 12:56:26 +00:00
Philip Withnall
0e5f9aa143 tests: Add more tests to finish branch coverage of GHashTable
Test a few situations where NULL values for optional out parameters
weren’t being tested. This takes the branch coverage of GHashTable up to
100% (ignoring g_return_if_fail() branches).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-31 12:46:48 +01:00
Philip Withnall
8dc8b33dfa ghash: Clear out arguments to NULL in g_hash_table_lookup_extended()
If the given key is not found, clear the orig_key and value arguments to
NULL as well as returning FALSE. Then the caller can unconditionally
check them.

This makes the behaviour of g_hash_table_lookup_extended() consistent
with g_hash_table_steal_extended().

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-31 12:46:48 +01:00
Philip Withnall
41a3951c8f Merge branch 'simplify-alloca-checks' into 'master'
build: simplify alloca checks. See #1313

See merge request GNOME/glib!268
2018-08-31 10:45:29 +00:00
Philip Withnall
eeadd57a14 glib: Remove remaining references to __int64
This is a follow-up to 7e821441c4 and
e154e3325e removing some remaining
references to __int64 which are no longer necessary.

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

https://gitlab.gnome.org/GNOME/glib/issues/1313
2018-08-31 11:41:12 +01:00
Ryan Schmidt
769b9a9c37 gspawn: Fix build on systems without O_CLOEXEC
Fixes typo introduced in 4afe429d7c.

See https://gitlab.gnome.org/GNOME/glib/issues/1488
2018-08-30 18:08:58 -05:00
Philip Withnall
297941e049 Merge branch 'ossfuzz-9805-variant-parser-overflow' into 'master'
gvariant: Fix more bounds checking in GVariant text format parser

See merge request GNOME/glib!239
2018-08-27 10:14:32 +00:00
Philip Withnall
3cafd7f266 Merge branch 'wip/chergert/garray-bail' into 'master'
garray: add overflow checks before expanding array

See merge request GNOME/glib!195
2018-08-27 10:09:58 +00:00
Philip Withnall
41cc3850ff dtrace: Add missing const attributes to types in glib_probes.d
This eliminates some ‘discards const qualifier’ warnings when compiling
on Solaris with --enable-dtrace.

See the log files in
https://gitlab.gnome.org/GNOME/glib/issues/1493#note_299037.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-25 23:59:45 +01:00
Christoph Reiter
11fcc2f1ac build: simplify alloca checks. See #1313
The goal of this commit is to reduce differences between the autotools and meson build.

With autotools AC_FUNC_ALLOCA was used which defines HAVE_ALLOCA_H, HAVE_ALLOCA,
C_ALLOCA. meson tried to replicate that with has_function() but alloca can be a macro
and and is named _alloca under Windows. Since we require a working alloca anyway
and only need to know if the header exists replace AC_FUNC_ALLOCA with a simple
AC_CHECK_HEADERS.

There is still one user of HAVE_ALLOCA in the embedded gnulib, but since alloca is
always provided through galloca.h just force define HAVE_ALLOCA there and add a comment.

The docs were mentioning alloca as an example for cross compiling. Since that variable no
longer exists now replace it with another one.
2018-08-24 10:57:10 +02:00
Simon McVittie
ec4da774e5 Merge branch '1492-cast-function-type-warning' into 'master'
glist: Mention -Wcast-function-type problems with g_*list_copy_deep()

Closes #1492

See merge request GNOME/glib!253
2018-08-23 09:25:36 +00:00
Philip Withnall
2e9c31af11 gmem: Only evaluate pointer argument to g_clear_pointer() once
The new typeof() macro version of g_clear_pointer() was evaluating its
pointer argument more than once, meaning any side effects would be
evaluated multiple times.

The existing (other) macro version of g_clear_pointer() was evaluating
its argument exactly once. This mismatch could have confused people or
lead to subtle bugs.

See https://gitlab.gnome.org/GNOME/glib/issues/1494.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-22 14:47:52 +01:00
Emmanuele Bassi
9a72ebe016 Merge branch '1494-clear-pointer-docs' into 'master'
gmem: Clarify calling convention behaviour of g_clear_pointer() in docs

Closes #1494

See merge request GNOME/glib!258
2018-08-22 11:22:58 +00:00
Philip Withnall
2bd09d56a2 Merge branch 'wip/sadiq/fixes' into 'master'
grefstring: Avoid an unnecessary NUL assignment

See merge request GNOME/glib!206
2018-08-22 11:21:23 +00:00
Emmanuele Bassi
c1d74052f5 Merge branch '1448-g-error-secretly-doesnt-abort' into 'master'
gmessages: Clarify documentation about aborting on fatal log levels

Closes #1448

See merge request GNOME/glib!254
2018-08-22 11:18:44 +00:00
Philip Withnall
c849a4ddd3 glib: Drop G_GNUC_MALLOC usage from various other allocation functions
These functions may be OK to leave the G_GNUC_MALLOC attribute on,
because the only valid pointers in the storage areas they return are,
themselves, new pointers.

However, it’s a lot easier to remove the attributes now than to try and
diagnose miscompilations in future. The performance impact of this is
likely to be unmeasurable. If there are performance problems caused by
this, then they can be profiled and fixed case-by-case in future,
bearing in mind the possibility for miscompilation if G_GNUC_MALLOC is
readded.

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

https://gitlab.gnome.org/GNOME/glib/issues/1465
2018-08-22 11:18:02 +01:00
Philip Withnall
082730fc3e glib: Drop G_GNUC_MALLOC usage from various allocation functions
These are our most critically incorrect uses of G_GNUC_MALLOC. See the
previous commit for details.

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

https://gitlab.gnome.org/GNOME/glib/issues/1465
2018-08-22 11:18:02 +01:00
Philip Withnall
c879f50f8a docs: Update the documentation for G_GNUC_MALLOC to reflect recent GCC
Thanks to some great investigation by Benjamin Moody, it’s clear that
our documentation and usage of G_GNUC_MALLOC has fallen behind GCC’s
interpretation of the malloc attribute, meaning that recent versions of
GCC could miscompile code which uses G_GNUC_MALLOC incorrectly.

Update the documentation of G_GNUC_MALLOC to match the current GCC
documentation (for GCC 8.2). Following commits will drop our use of
G_GNUC_MALLOC from inappropriate functions.

Specifically, the change in GCC’s interpretation of the malloc attribute
which could cause miscompilation is that returned storage areas are now
assumed to not contain valid pointers — so realloc() cannot have the
malloc attribute, and neither can a function which returns a newly
allocated structure with fields initialised to other pointers.

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

https://gitlab.gnome.org/GNOME/glib/issues/1465
2018-08-22 11:18:02 +01:00
Philip Withnall
a0456f9c96 gmessages: Clarify documentation about aborting on fatal log levels
Clarify that we actually raise SIGTRAP rather than calling abort(). We
haven’t called abort() since about 2011, when commit
a04efe6afb changed the logic to use
SIGTRAP to make it possible to skip past fatal log messages in the
debugger if they weren’t relevant to the problem being debugged.

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

https://gitlab.gnome.org/GNOME/glib/issues/1448
2018-08-22 10:37:15 +01:00
Philip Withnall
965bc6d857 gmem: Clarify calling convention behaviour of g_clear_pointer() in docs
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/1494
2018-08-22 10:28:47 +01:00
Christoph Reiter
63d3311c26 gstdio: use _stat64 for GStatBuf on 64bit mingw. Fixes #1476
The size of stat depends on various macros on Windows which leads to
the problem of size mismatches when glib is built with a different configuration
than a program using it.

For example the autotools build defaults to _FILE_OFFSET_BITS=64 and a program
not defining  _FILE_OFFSET_BITS will allocate a too small struct on the stack,
leading to stack corruption when glib writes to it.

To make the size the user sees always match the default mingw build define GStatBuf
as _stat64 (same as _FILE_OFFSET_BITS=64) under mingw+64bit.
2018-08-20 12:40:21 +02:00
Philip Withnall
282ad30c0c gslist: Fix a minor documentation syntax problem
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-20 11:00:54 +01:00
Philip Withnall
e81f4c2ace glist: Mention -Wcast-function-type problems with g_*list_copy_deep()
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/1492
2018-08-20 11:00:29 +01:00
Matthias Clasen
3664b017e3 Merge branch '1488-o-cloexec-again' into 'master'
gspawn: Use fcntl() to work around systems which don’t support O_CLOEXEC

Closes #1488

See merge request GNOME/glib!242
2018-08-16 12:31:27 +00:00
Philip Withnall
b1bfebc61c tests: Explicitly set TZ=UTC for g_time_val_from_iso8601() testing
Some of the test vectors don’t specify a timezone, so the local one is
used; the comparisons to the expected results (which are in UTC) then
fail.

See discussion in
https://gitlab.gnome.org/GNOME/glib/merge_requests/225.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-11 22:00:52 +01:00
Philip Withnall
4afe429d7c gspawn: Use fcntl() to work around systems which don’t support O_CLOEXEC
Somehow, we are still limping along with partial support for OS X
<10.7.

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

https://gitlab.gnome.org/GNOME/glib/issues/1488
2018-08-11 21:52:17 +01:00
Philip Withnall
8c844291b7 gtimer: Ensure arithmetic is correctly signed for ISO 8601 parsing
When calculating the value of a timezone offset, ensure that any offsets
done with negative numbers are done in a signed integer.

oss-fuzz#9815

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-10 10:43:37 +01:00
Philip Withnall
a9108f8bfd gvariant: Fix more bounds checking in GVariant text format parser
token_stream_prepare() was over-reading at the start of bytestring
literals (`b'blah'`).

Add tests for that, and for some other situations regarding bytestring
literal parsing, in order to try and get full branch coverage of that
bit of code.

oss-fuzz#9805

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-10 10:30:13 +01:00
Philip Withnall
10ee7301e8 gvariant: Fix bounds checking in GVariant text format parser
The token_stream_peek() functions were not doing any bounds checking, so
could potentially read 1 byte off the end of the input blob. This was
never noticed, since the input stream is almost always a nul-terminated
string. However, g_variant_parse() does allow non-nul-terminated strings
to be used with a @limit parameter, and the bugs become apparent under
valgrind if that parameter is used.

This includes modifications to the test cases to cover the
non-nul-terminated case.

Spotted by ossfuzz.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-09 01:08:46 +01:00
Emmanuele Bassi
291bb0c584 Merge branch '1433-rename-timezones-in-tests' into 'master'
tests: Don’t use a potentially-existent timezone in a test for failure

Closes #1433

See merge request GNOME/glib!213
2018-08-08 22:31:07 +00:00
Xavier Claessens
0498b43489 Merge branch '1446-g_test_init-docs' into 'master'
gtestutils: Mention G_DISABLE_ASSERT in documentation for g_test_init()

Closes #1446

See merge request GNOME/glib!212
2018-08-07 14:50:53 +00:00
Xavier Claessens
ba30f45d9a Merge branch 'timer-tests' into 'master'
Minor additions to gtimer.c tests

See merge request GNOME/glib!231
2018-08-07 14:43:43 +00:00
Philip Withnall
83c79eaf24 Merge branch 'smcv/glib-xfail'
Closes #1474

See merge request GNOME/glib!221
2018-08-07 12:24:16 +01:00
Simon McVittie
b8d751af3e testing: Exercise TAP output
(Tweaked by Philip Withnall <withnall@endlessm.com> to fix some minor
leaks, code formatting, and add a test comment.)

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-07 12:20:37 +01:00
Emmanuele Bassi
9ce18521aa Merge branch '1475-atomic-casts' into 'master'
tests: Fix a -Wbad-function-cast warning in the atomic tests

Closes #1475

See merge request GNOME/glib!223
2018-08-07 10:06:04 +00:00
Philip Withnall
6104e63ec4 tests: Improve branch coverage when testing g_time_val_add()
While I’m here…

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-07 11:03:39 +01:00
Philip Withnall
725eb1c86b tests: Add test for overflow handling in g_time_val_to_iso8601()
While I’m here…

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-07 11:03:39 +01:00
Emmanuele Bassi
7458defa9a Merge branch 'ossfuzz-9673-bookmark-date-overflow' into 'master'
gtimer: Add overflow checks to g_time_val_from_iso8601()

See merge request GNOME/glib!225
2018-08-07 09:57:21 +00:00
Philip Withnall
e5d9eca334 Merge branch 'gbytes-compare-docs' into 'master'
Fix up g_bytes_compare() documentation

See merge request GNOME/glib!229
2018-08-06 18:00:45 +00:00
Philip Withnall
2ab7fd2951 tests: Add more ISO 8601 parser tests
These come from looking at the code coverage data. We should now have
full branch coverage of the ISO 8601 parser.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-06 14:07:29 +01:00
Philip Withnall
fdccf5ff34 gtimer: Drop support for negative years from g_time_val_from_iso8601()
It never worked; we’ve always parsed the year with strtoul() (unsigned).
While negative years are supported by the ISO 8601 standard, they can
only be used by mutual agreement of the two parties interchanging data.
Moreover, they are not supported by GTimeVal, which is what we’re
filling with the results.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-06 14:07:29 +01:00
Philip Withnall
cefa66eb76 gtimer: Add overflow checks to g_time_val_from_iso8601()
The code was previously doing a few bits of arithmetic without checking
whether they would overflow, and hence not validating the date/time it
was parsing very strictly.

The parser is now not 100% strict, but should avoid any arithmetic
overflows which would cause an invalid result to be returned even though
g_time_val_from_iso8601() had returned TRUE.

oss-fuzz#9673

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-06 14:07:29 +01:00
Philip Withnall
b1fffbffbf gtimer: Document that g_time_val_from_iso8601() drops whitespace
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-06 14:07:29 +01:00
Philip Withnall
4eca2ac0ee tests: Add an overflow test for bookmark file dates
oss-fuzz#9673

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-06 14:07:27 +01:00
Philip Withnall
2860d4b50e gbookmarkfile: Fix some more minor leaks when metadata elements are repeated
oss-fuzz#9723

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-06 13:36:21 +01:00
Sebastian Dröge
a81b925d98 Fix up g_bytes_compare() documentation
It was declaring the opposite of what the function was actually doing,
and what every other comparison function is doing.
2018-08-06 15:20:02 +03:00
Simon McVittie
54a5f37f12 g_test_run: Document g_test_incomplete's similarity to g_test_skip
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 14:33:52 +01:00
Simon McVittie
0a180bb51b testing: Assert that test-case results are combined correctly
This repurposes the existing skip-all test as "combining", since it
is no longer entirely about runs where every test-case was skipped.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 14:30:10 +01:00
Simon McVittie
bbefa73997 testutils: Treat incomplete tests more like skipped tests
If a test is marked with g_test_incomplete(), then it is expected to
fail, so when it fails the test executable should still exit 0
(or possibly 77, if all tests are either skipped or incomplete).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 14:28:21 +01:00
Simon McVittie
ba3b442152 testing: Use g_assert_true(), which is preferred for unit tests
In the test for the unit testing framework, we might as well have
exemplary behaviour. Leave behind a single call to g_assert (TRUE)
just to prove that it still works.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 13:44:51 +01:00
Simon McVittie
ffe0402e02 testing: Assert that skipped tests cause g_test_failed()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 13:42:57 +01:00
Simon McVittie
49a877764d testing: Clarify why incomplete tests cause g_test_failed()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 13:42:38 +01:00
Simon McVittie
7cc5565e7c testutils: Correctly print incomplete tests as "not ok # TODO"
The TAP specification says that failing tests that are currently
expected to fail (like Automake's XFAIL) are to be reported as
"not ok", with that failure ignored as a result of the TODO
directive, with this example:

    not ok 3 - infinite loop # TODO halting problem unsolved

A test reported as "ok # TODO" indicates that something that is
expected to fail has unexpectedly succeeded, similar to Automake's
XPASS.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-03 13:20:59 +01:00
Philip Withnall
21d1797a4f tests: Fix a -Wbad-function-cast warning in the atomic tests
Assigning the gpointer return value from g_atomic_pointer_get() to a
gsize variable was not making -Wbad-function-cast happy. Assign to an
intermediate gpointer variable and then cast that instead.

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

https://gitlab.gnome.org/GNOME/glib/issues/1475
2018-08-03 11:08:26 +01:00
Simon McVittie
cc9cfc75fc date test: Use g_test_skip(), not g_test_incomplete()
g_test_skip() is appropriate for tests that can't run due to missing
functionality on the host system, whereas g_test_incomplete() is
for expected-to-fail tests for unimplemented functionality in the
code under test.

See also https://bugzilla.gnome.org/show_bug.cgi?id=793635 and
commit 5459b345.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-08-02 17:57:46 +01:00
Philip Withnall
71b0123845 Merge branch 'issue-1467' into 'master'
Drop a questionable test from the refstring suite

Closes #1467

See merge request GNOME/glib!218
2018-08-02 11:44:17 +00:00
Emmanuele Bassi
5e64ee3af7 Drop a questionable test from the refstring suite
Testing that an interned string is released once its last reference is
dropped is not possible without a hook into the interning machinery;
just checking that the returned pointer for the same string is going to
be different after the last release() is not guaranteed to work, as the
systema allocator is perfectly within its rights to recycle pointers, as
long as they are unique while valid.

Closes #1467
2018-08-02 12:21:38 +01:00
Philip Withnall
6c041ff283 gbookmarkfile: Fix some minor leaks when metadata elements are repeated
oss-fuzz#9674

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-08-02 11:20:15 +01:00
Philip Withnall
b2249bf33c tests: Don’t use a potentially-existent timezone in a test for failure
When checking that the timezone code falls back to UTC if a zone is
unknown, don’t use ‘PST’, because that can actually exist on some
systems.

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

https://gitlab.gnome.org/GNOME/glib/issues/1433
2018-07-31 19:54:56 +01:00
Philip Withnall
17df5c0b26 gtestutils: Mention G_DISABLE_ASSERT in documentation for g_test_init()
g_test_init() bails if G_DISABLE_ASSERT is defined. Mention that. This
is a follow-up to
https://gitlab.gnome.org/GNOME/glib/merge_requests/174.

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

https://gitlab.gnome.org/GNOME/glib/issues/1446
2018-07-31 19:49:37 +01:00
Philip Withnall
ca0110c34d build: Conditionally add spawn and IO channel without using EXTRA_ prefix
See previous commit; same reasoning behind the commit, except that these
sources weren’t (yet) causing `make distcheck` to fail.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-31 18:52:37 +01:00
Philip Withnall
862fe11f90 build: Conditionally add gwin32.c to sources without using EXTRA_ prefix
Instead of messing around with EXTRA_*_SOURCES and manually handling .lo
files, why not just add gwin32.c to the GLib sources conditionally?

This will hopefully fix `make distcheck` failing due to gwin32.Plo not
being generated in the sub-builddir≠srcdir stage, due to depcomp
inexplicably not generating it. (Note that it is correctly generated in
non-distcheck builds.)

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-31 18:52:37 +01:00
Philip Withnall
83c69fa77d Merge branch '1035-bookmarks-state-machine' into 'master'
gbookmarkfile: Fix error reporting with unexpected nesting of elements

Closes #1035

See merge request GNOME/glib!207
2018-07-30 22:50:52 +00:00
Matthias Clasen
dbf9959d15 Merge branch '1436-docs-muckery' into 'master'
Fix various documentation issues and man page issues with autotools

See merge request GNOME/glib!209
2018-07-30 22:24:26 +00:00
Philip Withnall
376234f9b2 gbookmarkfile: Fix error reporting with unexpected nesting of elements
The parser state machine for bookmark files did not handle unexpected
nesting of elements, such as a <bookmark> element inside a <title>
element — it would print a critical warning rather than returning a
GError.

Fix that, and add various unit tests for it. The set of tests includes
various other general markup tests as provided by Jussi Judin.

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

https://gitlab.gnome.org/GNOME/glib/issues/1035
2018-07-30 21:59:26 +01:00
Philip Withnall
b4734d3b5b docs: Add some more backtick quotation
That should format these character classes correctly in the
documentation, and prevent them being interpreted by gtk-doc as (broken)
Markdown hyperlinks.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 21:15:22 +01:00
Philip Withnall
fba8d7a48a docs: Fix case of a type used in a gtk-doc comment
This fixes the automatic linking of that type.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 21:15:03 +01:00
Philip Withnall
4cd7f769ae gconvert: Adjust an argument name in the header to match the source
This fixes a gtk-doc complaint about the argument name not matching
what’s used in the gtk-doc comment.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 21:14:16 +01:00
Philip Withnall
0e0b18e0cd docs: Fix a minor syntax error in a documentation comment
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 21:13:28 +01:00
Philip Withnall
2a69cdb1cd build: Stop distributing generated files in autotools tarballs
It is a bug if we distribute files which are generated at build time —
they should be built on the machine which is compiling GLib, not be
shipped in the tarball.

This brings the autotools-generated tarball in line with the
ninja-generated one, with the exception of man pages and gtk-doc HTML
output.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 19:58:24 +01:00
Philip Withnall
47dcbd318f build: Remove a pointless intermediate variable in glib/Makefile.am
This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-30 19:47:15 +01:00
Matthias Clasen
4127c84c3a Merge branch '1461-bookmarks-nullptr' into 'master'
gmarkup: Fix crash in error handling path for closing elements

Closes #1461

See merge request GNOME/glib!205
2018-07-30 18:44:48 +00:00
Matthias Clasen
f424a0c2d3 Merge branch '1462-bookmark-overflow' into 'master'
gmarkup: Fix unvalidated UTF-8 read in markup parsing error paths

Closes #1462

See merge request GNOME/glib!204
2018-07-30 17:56:21 +00:00
Mohammed Sadiq
f0ce956f73 grefstring: Avoid an unnecessary NUL assignment
The duped string is already NUL-terminated.
There is no need to do it again.
2018-07-30 23:06:23 +05:30
Philip Withnall
fccef3cc82 gmarkup: Fix crash in error handling path for closing elements
If something which looks like a closing tag is left unfinished, but
isn’t paired to an opening tag in the document, the error handling code
would do a null pointer dereference. Avoid that, at the cost of
introducing a new translatable error message.

Includes a test case, courtesy of pdknsk.

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

https://gitlab.gnome.org/GNOME/glib/issues/1461
2018-07-30 18:33:39 +01:00
Philip Withnall
cec7170540 gmarkup: Fix unvalidated UTF-8 read in markup parsing error paths
When formatting the error messages for markup parsing errors, the parser
was unconditionally reading a UTF-8 character from the input buffer —
but the buffer might end with a partial code sequence, resulting in
reading off the end of the buffer by up to three bytes.

Fix this and add a test case, courtesy of pdknsk.

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

https://gitlab.gnome.org/GNOME/glib/issues/1462
2018-07-30 18:10:25 +01:00
Philip Withnall
ef1d24974d gasyncqueue: Add missing precondition to g_async_queue_timeout_pop()
And g_async_queue_timeout_pop_unlocked().

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

https://gitlab.gnome.org/GNOME/glib/issues/1459
2018-07-30 17:18:03 +01:00
Mohammed Sadiq
e91da3fc77 grcbox: Fix typo in doc 2018-07-30 12:39:27 +05:30
Christian Hergert
0c7dc75844 garray: add overflow checks before expanding array
We should bail when we detect that adding a number of items to an array
would cause it to overflow. Since we can't change to using gsize for ABI
reasons we should protect the integrity of the process even if that means
crashing.
2018-07-23 21:05:11 -07:00
Rico Tzschichholz
c79c234c35 unicode: Update to unicode 11.0.0
Fixes https://gitlab.gnome.org/GNOME/glib/issues/1407
2018-07-18 14:26:47 +02:00
Philip Withnall
532c45b5ce tests: Skip some more date tests if translations are not installed
These tests will work if the glibc translations are up to date, or if
the GLib translations are installed and up to date; but not if neither
are in place.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

https://gitlab.gnome.org/GNOME/glib/issues/1447
2018-07-17 20:51:47 +02:00
Philip Withnall
27eb6b4290 tests: Compare month names case-insensitively in date tests
This has the same rationale as the corresponding change to the gdatetime
tests; commit 9cadb90b35.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

https://gitlab.gnome.org/GNOME/glib/issues/1447
2018-07-17 20:51:47 +02:00
Philip Withnall
e487df31e1 gvariant: Fix some memory leaks on error paths
Coverity CID: #1393955
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2018-07-17 12:14:36 +02:00
Philip Withnall
7f55c768ce Merge branch '1444-install-tests' into 'master'
Install unit tests

Closes #1444

See merge request GNOME/glib!183
2018-07-17 09:51:12 +00:00
Philip Withnall
16c6a73586 Merge branch 'add-g-has-typeof-1440' into 'master'
gmacros: Add new private g_has_typeof to abstract __typeof__ checks

Closes #1440

See merge request GNOME/glib!172
2018-07-17 09:27:12 +00:00
Philip Withnall
4dc6a01241 Merge branch 'type-safe-g-clear-pointer-1425' into 'master'
Type safe g clear pointer 1425

Closes #1425

See merge request GNOME/glib!177
2018-07-17 09:23:29 +00:00
Xavier Claessens
1bba3276bb Meson: Install glib tests
Fixes: #1444.
2018-07-16 15:36:20 -04:00
Xavier Claessens
a84cbf1434 Meson: Group all glib tests into a single dict 2018-07-16 15:33:58 -04:00
Xavier Claessens
5f3db543f8 Meson: Remove hack that got fixed a while ago 2018-07-16 15:04:03 -04:00
Xavier Claessens
f456e311cd Meson: Use environment() for test_env 2018-07-16 15:04:03 -04:00
Iain Lane
4c621fb7ee gmacros: Add new private g_has_typeof to abstract __typeof__ checks
We have this same check in a few places now, and we might as well
abstract it out.

Fixes #1440.
2018-07-16 15:59:44 +01:00
Iain Lane
f9a9902aac gmem.h: Use __typeof__() in the g_clear_pointer() macro
Type punning is used on the existing implementation, which hides errors
such as:

  GSList *list = NULL;
  g_clear_pointer (&list, g_error_free);

Let's use __typeof__ to cast the passed-in pointer before it's passed to
the free function so it trips -Wincompatible-pointer-types if it's wrong.

Fixes #1425
2018-07-16 15:34:27 +01:00
Emmanuele Bassi
d91d18cc78 Merge branch '976-disable-assert-checks' into 'master'
Document difference between g_assert() and g_assert_*() wrt G_DISABLE_ASSERT

Closes #976

See merge request GNOME/glib!174
2018-07-13 16:00:18 +00:00
Xavier Claessens
c96f987f0d Merge branch '786-gio-test-leaks' into 'master'
Fix memory leaks in libgio tests and ensure tests are run under Meson

Closes #786

See merge request GNOME/glib!151
2018-07-13 15:46:21 +00:00
Philip Withnall
b9d390dc44 Merge branch 'indentation_correction_gspawn' into 'master'
gspawn: correct indentation in do_posix_spawn

See merge request GNOME/glib!180
2018-07-13 12:21:13 +00:00
Thomas Hindoe Paaboel Andersen
102bcaffa2 gspawn: correct indentation in do_posix_spawn
The indentation was slightly wrong for this section when introduced
in commit 61f54591ac
2018-07-13 13:37:11 +02:00
Philip Withnall
b7f7f75bf1 Merge branch '889-stdiowrappers-symlink-failure' into 'master'
tests: Fix running fileutils test in cwd which is a symlink

Closes #889

See merge request GNOME/glib!170
2018-07-13 11:20:53 +00:00
Thomas Hindoe Paaboel Andersen
a8b416f9fe python: avoid equality check for None
PEP8 says that:
"Comparisons to singletons like None should always be done with is or
is not, never the equality operators."

glib uses a mix of "== None" and "is None". This patch changes all
cases to the latter.
2018-07-12 23:48:41 +02:00
Emmanuele Bassi
d3881bb1bf Revert "Merge branch 'type-safe-g-clear-pointer-1425' into 'master'"
This reverts merge request !165
2018-07-11 21:52:31 +00:00
Philip Withnall
08f41d802a Merge branch 'type-safe-g-clear-pointer-1425' into 'master'
gmem.h: Use __typeof__() in the g_clear_pointer() macro

Closes #1425

See merge request GNOME/glib!165
2018-07-11 15:57:55 +00:00
Philip Withnall
ca23acdb24 gtestutils: Bail out of g_test_init() if G_DISABLE_ASSERT is defined
If G_DISABLE_ASSERT is defined, g_assert() is a no-op. Despite it now
being standard practice to *not* use g_assert() in unit tests (use
g_assert_*() instead), a lot of existing unit tests still use it.
Compiling those tests with G_DISABLE_ASSERT would make them silently
no-ops. Avoid that by warning the user loudly.

Note that it’s pretty rare for people to compile with G_DISABLE_ASSERT,
so it’s not expected that this will be hit often.

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

https://gitlab.gnome.org/GNOME/glib/issues/976
2018-07-11 17:41:46 +02:00
Philip Withnall
51ce8d204c gtestutils: Document difference between g_assert() and g_assert_*()
g_assert() must not be used in tests. g_assert_*() must not be used in
production code.

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

https://gitlab.gnome.org/GNOME/glib/issues/976
2018-07-11 17:29:49 +02:00
Philip Withnall
d1d17e83c6 tests: Fix running fileutils test in cwd which is a symlink
If the fileutils test was run in a directory which is a symlink (for
example, on macOS, /tmp is often a symlink to /private/tmp), a path
comparison was failing. Compare the paths as inodes instead.

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

https://gitlab.gnome.org/GNOME/glib/issues/889
2018-07-11 15:43:22 +02:00
Philip Withnall
c182cd68c9 Merge branch 'sign-compare' into 'master'
Fix some -Wsign-compare warnings

See merge request GNOME/glib!162
2018-07-11 10:07:34 +00:00
Philip Withnall
a5d9fd2900 Merge branch '1044-prlimit-fix' into 'master'
Fix prlimit() error handling in tests

Closes #1044

See merge request GNOME/glib!164
2018-07-11 10:03:44 +00:00
Iain Lane
0da6265939 gmem.h: Use __typeof__() in the g_clear_pointer() macro
Type punning is used on the existing implementation, which hides errors
such as:

  GSList *list = NULL;
  g_clear_pointer (&list, g_error_free);

Let's use __typeof__ to cast the passed-in pointer before it's passed to
the free function so it trips -Wincompatible-pointer-types if it's wrong.

Fixes #1425
2018-07-11 10:52:53 +01:00
Philip Withnall
17e6a3a2f4 gvariant: Fix -Wsign-compare warnings
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-11 10:43:17 +02:00
Philip Withnall
6be9f065cb tests: Fix error reporting on prlimit() call failure
prlimit() returns its error code in errno, not as a return value.

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

https://gitlab.gnome.org/GNOME/glib/issues/1044
2018-07-11 10:06:06 +02:00
Philip Withnall
3475afc255 Merge branch '1402-real-time' into 'master'
glib: Don’t use time(NULL) to get current time

Closes #1402

See merge request GNOME/glib!154
2018-07-11 07:51:06 +00:00
Philip Withnall
194df27f5a gatomic: Tweak __atomic_load*() calls to work with -Wbad-function-cast
When compiling third-party projects with -Wbad-function-cast, the inline
g_atomic_pointer_get() implementation which uses C11 __atomic_load*()
calls on GCC was causing compilation errors like:

   error: cast from function call of type ‘long unsigned int’ to non-matching type ‘void *’

While we don’t want to compile all of GLib with -Wbad-function-cast, we
should support its headers being included in projects which do enable
that warning.

It doesn’t seem to be possible to cast away the warning (e.g. by casting
the function’s result through (void)), so we have to assign to an
intermediate integer of the right size first.

The same has to be done for the bool return value from
__sync_bool_compare_and_swap(). In that case, casting from bool to
gboolean raises a -Wbad-function-cast warning, since gboolean is
secretly int.

The atomic tests have been modified to enable -Wbad-function-cast to
catch regressions of this in future. The GLib build has conversely been
modified to set -Wno-bad-function-cast, just in case people have it set
in their environment CFLAGS.

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

https://gitlab.gnome.org/GNOME/glib/issues/1041
2018-07-10 17:49:16 +02:00
Philip Withnall
91c0c6f95b grand: Fix -Wsign-compare warning
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-10 14:16:41 +02:00
Philip Withnall
e40e77f9be gqueue: Fix -Wsign-compare warnings
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-10 14:16:24 +02:00
Philip Withnall
03bad78947 garray: Fix -Wsign-compare warnings
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-10 14:15:42 +02:00
Richard Hughes
dad58d7392 Add a g_ref_string_new_len() to allow creating from non-NUL byte arrays
A lot of GLib APIs provide a string length and explicitly say that the strings
are not NUL terminated. For instance, parsing XML using GMarkupParser or
reading packed binary strings from mmapped data files.
2018-07-09 15:59:39 +01:00
Philip Withnall
92e059280f glib: Don’t use time(NULL) to get current time
Use either g_get_real_time() or g_date_time_new_now_local(). This means
we don’t need to worry about time_t being 32b in future (the year 2038
problem), and it makes the need for error handling a bit more explicit.
Improve the error handling in several cases.

Based on a patch by Niels De Graef
(https://gitlab.gnome.org/GNOME/glib/merge_requests/142).

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

https://gitlab.gnome.org/GNOME/glib/issues/1402
2018-07-09 13:28:02 +02:00
Emmanuele Bassi
822b511cb6 Update rcbox annotations for acquire/release functions
The accepted behaviour for reference counting functions can be described
as such:

 - acquire: takes a pointer to a memory area and returns the same
   pointer with its reference count increased; this means that the
   returned value's ownership is fully transfered from the callee
   to the caller
 - release: takes a pointer to a memory area and drops the reference
   count; this means that the caller transfers the ownership of the
   argument to the callee

These annotations are mostly meant for documentation purposes: high
level language bindings are unlikely to use them, as they have their own
reference counting semantics on top of GLib's own, and they should not
expose this API to their own consumers.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
0d00667d01 Increase coverage of atomic refcounted data
We are not testing the API directly, and this leads to holes in the code
coverage.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
37687941eb Increase coverage for GRefString
We still have some holes in the code coverage of the GRefString test
suite.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
cfe962a5dc Add missing trasfer annotation for g_ref_string_new()
We don't have one, but we ought to.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
18605db3ac Allow empty strings to be refcounted 2018-07-09 10:11:42 +01:00
Emmanuele Bassi
c342105e76 Add systemtap probes to refcounted data
Probes allow us to debug refcounting bugs.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
4248b4b300 Fix the implementation of interned refstrings
The global hash table we use for interned strings should not own a
reference on the strings themselves, as otherwise we'd leak them all
over the place.

Instead, it should keep a "weak" reference to them; once the last
strong reference goes away, we drop remove the weak reference from the
hash table.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
501a8e96e8 Add missing copyright notice 2018-07-09 10:11:42 +01:00
Emmanuele Bassi
61ca2e4c85 Check for overflow when allocating RcBox
Since we're over-allocating the passed block size, we need to check that
we're not overflowing gsize when computing the actual allocation size.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
7c4ac58938 Allow NULL clear function when releasing references
Both g_rc_box_release_full() and g_atomic_rc_box_release_full() should
allow passing NULL as the clear function, to conform to the existing
coding practices in GLib.

Additionally, this allows us to reimplement release() in terms of
release_full(), and improve test coverage.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
68304ae583 Improve docs for g_rc_box/g_atomic_rc_box
Especially the preconditions and the annotations for the returned
values.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
3bc0499eb2 Rename g_arc_box to g_atomic_rc_box
Makes the API more self-explanatory.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
32ecb86f5b Add length accessor for GRefString
Since we store the size of the allocation in the underlying ArcBox, we
can get a constant time getter for the length of the string.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
43b7a8f158 Add size accessor to RcBox and ArcBox
It may be useful to know how big a reference counted allocation is
outside of internal checks.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
00a723f597 Add reference counted strings
The last part of the reference counting saga.

Now that we have:

 - reference counter types
 - reference counted allocations

we can finally add reference counted strings using reference counted
allocations to avoid creating a new String type, and reimplementing
every single string-based API.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
4b33b03dd3 Improve the RcBox and ArcBox documentation
Use better examples, split up into sections, and mention use with
g_autoptr().
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
8990c3c4d3 Make g_rc_box_dup()/g_arc_box_dup() more generic
It's more useful to have a dup() function that copies any blob of memory
into a reference counted allocation, than to have a dup() that only
copies a reference counted allocation.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
b607927a43 Add atomically refcounted data
GArcBox is the atomic reference counting version of GRcBox. Unlike
GRcBox, the reference acquisition and release on GArcBox are guaranteed
to be atomic, and thus they can be performed from different threads.

This is similar to Rust's Arc<Box<T>> combination of traits.
2018-07-09 10:11:42 +01:00
Emmanuele Bassi
c5d2417d07 Add refcounted data
It is useful to provide a "reference counted allocation" API that can
add reference counting semantics to any memory allocation. This allows
turning data structures that usually are placed on the stack into memory
that can be placed on the heap without:

 - adding a public reference count field
 - implementing copy/free semantics

This mechanism is similar to Rust's Rc<Box<T>> combination of traits,
and uses a Valgrind-friendly overallocation mechanism to store the
reference count into a private data segment, like we do with GObject's
private instance data.
2018-07-09 10:11:42 +01:00
Philip Withnall
b1e0f09e7d tests: Add missing unit test to GLib tests list
It must have been accidentally omitted during the Meson port.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-06 14:58:57 +01:00
Xavier Claessens
2a1404ac21 Merge branch '977-checksum-constants' into 'master'
gchecksum: Use G_GUINT64_CONSTANT for SHA-512 constants

Closes #977

See merge request GNOME/glib!146
2018-06-29 20:17:55 +00:00
Philip Withnall
9470aa2cb9 gchecksum: Use G_GUINT64_CONSTANT for SHA-512 constants
They’re all 8 bytes long, and integer constants that large need a suffix
on 32-bit platforms.

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

https://gitlab.gnome.org/GNOME/glib/issues/977
2018-06-29 18:26:00 +01:00
Daniel Drake
16c3409888 gspawn: treat all negative fds as unset
Philip Withnall suggests that glib should treat all negative
file descriptors as unset/invalid, rather than explicitly requiring
them to be -1.

This can simplify the logic for some users of this code.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/132
2018-06-29 11:44:12 -05:00
Philip Withnall
4dc927fc2f Merge branch 'ci-memcheck-preparation' into 'master'
Preparation for adding valgrind/memcheck to CI

See merge request GNOME/glib!143
2018-06-29 13:31:43 +00:00
Philip Withnall
6a22663d9a tests: Various minor leak fixes in the GLib tests
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-29 12:13:32 +01:00
Philip Withnall
0ea541171d Merge branch '903-deprecate-main-context-wait' into 'master'
gmain: Officially deprecate g_main_context_wait()

Closes #903

See merge request GNOME/glib!139
2018-06-28 16:59:39 +00:00
Philip Withnall
7a34e396ae gmain: Officially deprecate g_main_context_wait()
It’s been de-facto deprecated for a long time, due to emitting a
critical warning when used in a non-internal context. Make that official
in the documentation and with a deprecation annotation.

Split the implementation into an internal helper and an external
wrapper, so the two remaining internal uses don’t emit deprecation
warnings.

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

https://gitlab.gnome.org/GNOME/glib/issues/903
2018-06-26 09:30:19 +01:00
Philip Withnall
208a6e815a gmain: Add names to various GSources constructed in GLib
For the purposes of debugging, it is quite useful for every GSource to
have a name set. Ensure that any GSource we construct inside GLib has a
name set. For GSources which are then returned to the caller, this name
can then be overridden with something even more useful by the caller.

Since this data is only used for debugging, avoid doing any allocations
for it; just use static strings.

https://gitlab.gnome.org/GNOME/glib/issues/1175
2018-06-26 09:25:39 +01:00
Piotr Drąg
d9fc99256e Use Unicode typography in new translatable strings
See https://developer.gnome.org/hig/stable/typography.html
2018-06-25 16:51:00 +02:00
Philip Withnall
509ced6be5 Merge branch 'source-get-id-docs' into 'master'
gmain: Clarify documentation for g_source_get_id()

See merge request GNOME/glib!128
2018-06-25 13:18:32 +00:00
Philip Withnall
515dac258c gmain: Clarify documentation for g_source_get_id()
It’s good to know *which* GMainContext is used to determine the ID, and
the preconditions for calling this method.

Using wording suggested by Emmanuele Bassi <ebassi@gmail.com>.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-25 13:46:43 +01:00
Ting-Wei Lan
e14c853d9a gspawn: Declare environ
Function do_posix_spawn uses environ, but gspawn.c doesn't declare it.
Since there is no system header declaring this global variable, this
causes compilation error on FreeBSD.

Code added in this commit is copied from genviron.c.
2018-06-23 16:11:19 +08:00
Philip Withnall
0f77dc847b Merge branch 'wip/Jehan/fopen-modes' into 'master'
glib: Win32 does not accept "wb+" mode for fopen().

See merge request GNOME/glib!119
2018-06-22 17:24:14 +00:00
Jehan
ef4063c74d glib: add test for various modes of fopen().
This is especially to check for Win32 spotty support of "+" modes, such
as "wb+" which has to be replaced by "w+b".
See merge request !119.
2018-06-22 16:40:21 +02:00
Philip Withnall
ca98ce4280 Merge branch 'master' into 'master'
Use posix_spawn for optimized process launching

See merge request GNOME/glib!95
2018-06-21 17:10:43 +00:00
Daniel Drake
2b560457a0 gspawn: use sane_open() for stdin
sane_open() is used for stdout and stderr, but regular open() was being
used for stdin. Spotted by Philip Withnall.
2018-06-21 11:44:59 -05:00
Daniel Drake
86e2b8d427 gspawn: document FD_CLOEXEC behaviour
G_SPAWN_LEAVE_DESCRIPTORS_OPEN must be set to enable the optimized
posix_spawn codepath, so this flag is likely to see more usage now.

Document that FD_CLOEXEC can be used to cause file descriptors to be
automatically closed while this flag is used.
2018-06-21 11:44:59 -05:00
Daniel Drake
61f54591ac gspawn: Optimize with posix_spawn codepath
When the amount of free memory on the system is somewhat low, gnome-shell
will sometimes fail to launch apps, reporting the error:
  fork(): Cannot allocate memory

fork() is failing here because while cloning the process virtual address
space, Linux worries that the thread being forked may end up COWing the
entire address space of the parent process (gnome-shell, which is
memory-hungry), and there is not enough free memory to permit that to
happen.

In this case we are simply calling fork() in order to quickly call exec(),
which will throw away the entirity of the duplicated VM, so we should
look for ways to avoid the overcommit check.

The well known solution to this is to use clone(CLONE_VM) or vfork(), which
completely avoids creating a new memory address space for the child.
However, that comes with a bunch of caveats and complications:

  https://gist.github.com/nicowilliams/a8a07b0fc75df05f684c23c18d7db234
  https://ewontfix.com/7/

In 2016, glibc's posix_spawn() was rewritten to use this approach
while also resolving the concerns.
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9ff72da471a509a8c19791efe469f47fa6977410

I experimented with a similar approach in glib, but it was not practical
because glibc has several items of important internal knowledge (such as
knowing which signals should be given special treatment because they are
NPTL implementation details) that are not cleanly exposed elsewhere.

Instead, this patch adapts the gspawn code to use posix_spawn() where
possible, which will reap the benefits of that implementation.
The posix_spawn API is more limited than the gspawn API though,
partly due to natural limitations of using CLONE_VM, so the posix_spawn
path is added as a separate codepath which is only executed when the
conditions are right. Callers such as gnome-shell will have to be modified
to meet these conditions, such as not having a child_setup function.

In addition to allowing for the gnome-shell "Cannot allocate memory"
failure to be avoided, this should result in a general speedup in this
area, because fork()'s behaviour of cloning the entire VM space
has a cost which is now avoided. posix_spawn() has also recently
been optimized on OpenSolaris as the most performant way to spawn
a child process.
2018-06-21 11:43:32 -05:00
Daniel Drake
3524de16e4 gspawn: Add g_spawn_async_with_fds variant
Add a new process spawning function variant which allows the caller
to pass specific file descriptors for stdin, stdout and stderr.
It is otherwise identical to g_spawn_async_with_pipes.

Allow the same fd to be passed in multiple parameters. To make this
workable, the child process logic that closes the fd after the first time
it has been dup2'ed needed tweaking; we now just set those fds to be
closed upon exec using the CLOEXEC flag. Add a test for this case.

This will be used by gnome-shell to avoid performing equivalent
dup2 actions in a child_setup function. Dropping use of child_setup will
enable use of an upcoming optimized process spawning codepath.
2018-06-21 11:43:32 -05:00
Jehan
2b6bfdb125 glib: Win32 does not accept "wb+" mode for fopen().
Nevertheless it accepts "w+b".
When checking the Win32 documentation of fopen()/_wfopen(), it clearly
states:
> In addition to the earlier values, the following characters can be
> appended to mode to specify the translation mode for newline
> characters.

This implementation expects 'b' or 't' to be appended, and therefore
"wb+" ends up with an error, whereas the alias "w+b" works perfectly
while it is exactly the same thing. So let's just have glib "translate"
the mode when it can to have it working transparently the same way on
every platform.
2018-06-21 13:55:19 +02:00
Philip Chimento
9e46b2ef11 gtester: Explicitly convert arguments of g_assert_cmpfloat()
Using g_assert_cmpfloat() with a float or double causes warnings on the
newest Clang version, because the macro internally promotes all values to
a long double, which Clang warns about. Casting explicitly removes the
warning.

Closes: #1377
2018-06-21 00:20:55 -07:00
Philip Withnall
0b9cdf07f7 Merge branch 'lrn/attachconsole' into 'master'
W32: add std stream redirection envvar options

Closes #1304

See merge request GNOME/glib!104
2018-06-20 11:21:43 +00:00
Руслан Ижбулатов
460cc723ad W32: add std stream redirection envvar options
This commit adds two W32-only environmental variable checks:
* G_WIN32_ALLOC_CONSOLE, if set to 1, will force glib to create
  a new console if the process has no console by itself.
  This option is for GUI apps that are launched from GUI
  processes, in which case there's no console anywhere near them.
* G_WIN32_ATTACH_CONSOLE, if set to a comma-separated list of
  standard stream names (stdint, stdout, stderr), will reopen
  a given std stream and tie it to the console (using existing console
  or parent console).
  This works either with the other option (to create a console),
  or if the app is launched from a console process (often the
  case for developers).
  The redirection is done with freopen(), dup() and dup2().
  If everything goes well, C file descriptors 0, 1 or 2 will
  be bound to stdin, stdout and stderr respectively (only for
  streams listed in the envrionmental variable), and so will
  be stdio streams by the same names.

With these it's possible to see the output of g_log*() functions
when running GTK4 applications, which are linked as GUI applications,
and thus do not get a console by default.

https://bugzilla.gnome.org/show_bug.cgi?id=790857

Fixes issue #1304
2018-06-20 10:53:30 +00:00
Emmanuele Bassi
df28cfe0b5 Merge branch '896-variant-type-docs' into 'master'
Documentation and typing improvements for GVariant bytes

Closes #896

See merge request GNOME/glib!117
2018-06-19 14:15:37 +00:00
Philip Withnall
dd51b05e19 Merge branch 'non-atomicity-of-g_file_set_contents' into 'master'
gfileutils: document non-atomicity of g_file_set_contents()

See merge request GNOME/glib!118
2018-06-19 11:13:50 +00:00
Xavier Claessens
75fd0109db Merge branch 'str-equal-docs' into 'master'
docs: Amend the docs for g_str_equal() to reflect current general usage

See merge request GNOME/glib!109
2018-06-15 14:53:19 +00:00
Will Thompson
c1a8e93dc4
gfileutils: document non-atomicity of g_file_set_contents()
This function only calls fsync() if @target exists and is non-empty. If
not, it doesn't provide the "old contents or new contents" guarantee
that one might expect. This has been the case since
d20a188b12, and is justified either as a
performance optimization or by asserting that this function only
guarantees to not destroy existing data (implicitly defining
non-existence or emptiness as not data).

In addition, explicitly spell out that whether it's atomic in the
non-empty case is system-dependent. If the system administrator has
configured some funky filesystem options, they may be out of luck on the
atomicity front.

https://gitlab.gnome.org/GNOME/glib/issues/1302
2018-06-15 14:47:47 +01:00
Philip Withnall
09419fdeb4 gvariant: Change type of ‘y’ variants from guchar to guint8
This fits better with the convention in the rest of GLib where arbitrary
8-bit values are represented as guint8, avoiding the potential confusing
of a name which references ‘char’s.

This is not an API break, as both guint8 and guchar are unconditionally
typedeffed to unsigned char.

https://gitlab.gnome.org/GNOME/glib/issues/896
2018-06-15 13:10:36 +01:00
Philip Withnall
ac690d9a8c docs: Amend the docs for g_str_equal() to reflect current general usage
People do (and should) use g_str_equal() for string comparisons outside
of hash tables, because it’s easier to read than
`strcmp (str1, str2) == 0`. That should not be discouraged.

However, we should still be careful to point out that g_str_equal() is
not NULL-safe, and g_strcmp0() is.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-14 18:12:42 +01:00
Nathan Miller
0b09890bff goption: Reject group options specified with three dashes
Commandline option parsing would recognize group options specified
with three dashes (i.e. ---foo 42).  This behaviour was limited to group
options.
2018-06-14 10:49:31 -05:00
Philip Withnall
d8c003dea6 Merge branch 'G_SOURCE_FUNC-macro' into 'master'
Add G_SOURCE_FUNC cast macro which suppresses -Wcast-function-type

See merge request GNOME/glib!82
2018-06-14 09:34:12 +00:00
Will Thompson
039fa6897b
Add G_SOURCE_FUNC cast macro which suppresses -Wcast-function-type
This is the workaround suggested by
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wcast-function-type

This warning is not enabled by default during the GLib build, but
applications may want to opt into it.
2018-06-14 10:11:12 +01:00
Philip Withnall
d157102a54 gspawn: Factor out error code conversion function
This will be used in gspawn-win32.c too in an upcoming commit.

https://gitlab.gnome.org/GNOME/glib/issues/303

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-12 16:13:51 +01:00
Philip Withnall
6c8da69443 gspawn: Make error codes on Windows more specific
A slightly modified patch originally written by Morten Welinder
<terra@gnome.org> to make the error codes returned by g_spawn_*()
functions more specific when on Windows. They are already this specific
on Linux.

Add a unit test for the ENOENT case.

https://gitlab.gnome.org/GNOME/glib/issues/303

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-12 16:13:44 +01:00
Philip Withnall
f4d2051fc1 gspawn: Fix errno saving in Windows implementation
The error number was saved after some g_debug() and g_free() calls, in
various places, which meant it could have been overwritten since the
error we care about happened.

https://gitlab.gnome.org/GNOME/glib/issues/303

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-12 15:33:35 +01:00
Philip Withnall
54498aa7ae Merge branch 'lrn/binary-tests' into 'master'
Force binary mode for stdout in printf tests

See merge request GNOME/glib!89
2018-06-11 15:06:25 +00:00
Руслан Ижбулатов
ce1e32ec34 Force binary mode for stdout in printf tests
This allows test calls to produce output with \n
line separators on Windows, instead of \r\n.
Reduces the number of ifdefs, since all checks
can be done against one template on all platforms.
2018-06-11 14:20:34 +00:00
Emmanuele Bassi
927de4433e Port GHashTable to gatomicrefcount
Use the newly added API for reference counting instead of rolling our
own.
2018-06-11 14:59:39 +01:00
Emmanuele Bassi
e67e4cb849 Port GBytes to gatomicrefcount
Use the newly added API for reference counting instead of rolling our
own.
2018-06-11 14:59:39 +01:00
Emmanuele Bassi
439ee4822e Port GArray and friends to gatomicrefcount
Use the newly added API for reference counting instead of rolling our
own.
2018-06-11 14:59:39 +01:00
Emmanuele Bassi
09e2247d3f Add tests for refcount types
Test that the API behaves as expected, especially when we get to
saturation.

Additionally, check that both the function and the macro versions of the
API behave identically.
2018-06-11 14:59:39 +01:00
Emmanuele Bassi
827c208cbf Use macros for refcount types API
If we're using GCC we can use __extension__ to inline the grefcount and
gatomicrefcount API, and avoid the function call.

These macros are only enabled if G_DISABLE_CHECKS is defined, as they
remove critical warnings when the reference counters achieve saturation.
2018-06-11 14:59:39 +01:00
Emmanuele Bassi
9e5a53d576 Add reference counting types
We have a common pattern for reference counting in GLib, but we always
implement it with ad hoc code. This is a good chance at trying to
standardise the implementation and make it public, so that other code
using GLib can take advantage of shared behaviour and semantics.

Instead of simply taking an integer variable, we should create type
aliases, to immediately distinguish the reference counting semantics of
the code; we can handle mixing atomic reference counting with a
non-atomic type (and vice versa) by using differently signed values for
the atomic and non-atomic cases.

The gatomicrefcount type is modelled on the Linux kernel refcount_t
type; the grefcount type is added to let single-threaded code bases to
avoid paying the price of atomic memory barriers on reference counting
operations.
2018-06-11 14:59:39 +01:00
Paul Eggert
137dd7789b gtimezone: port to tzcode 2014c
Problem reported by Marien Zwart in:
https://gitlab.gnome.org/GNOME/glib/issues/878
Derived from a fix by John Ralls proposed in that bug report.
2018-06-11 14:30:16 +01:00
Philip Withnall
ad957b6630 Merge branch 'wip/piotrdrag/unicode-typography' into 'master'
Fix tests for Unicode strings

Closes #1212

See merge request GNOME/glib!75
2018-06-11 11:03:43 +00:00
Emmanuele Bassi
16d1a3d28c Classify the tests
Meson has the ability to classify tests according to "suites", a list of
tags. This is especially useful when we want to run specific sets of
tests — e.g. only GLib's tests — instead of the whole test suite. It
also allows us to classify special tests, like "slow" ones, so that we
can only run them when needed.
2018-06-10 15:33:06 +01:00
Piotr Drąg
b974cccdaf Revert "Partially revert 10c490cdfe3ae042f747bd00f787492e2bdb7ed0"
This reverts commit 2d56c49b10.
2018-06-08 16:15:54 +02:00
Piotr Drąg
0bb3cacacb Fix tests for Unicode strings
Based on a patch by Simon McVittie <simon.mcvittie@collabora.co.uk>.

Fixes: https://gitlab.gnome.org/GNOME/glib/issues/1212
2018-06-08 16:13:52 +02:00
Christoph Reiter
bb92a03d68 Merge branch 'array-allocations' into 'master'
garray: Optimise over-allocations with g_array_insert_vals()

See merge request GNOME/glib!53
2018-06-07 08:06:15 +00:00
Chun-wei Fan
4bb173b297 build: Remove leftovers of Visual Studio project stuff
There are more leftover preconfigured stuff that we ought to remove...
2018-06-06 23:54:13 +08:00
Chun-wei Fan
efd19088b0 Drop config.h.win32.in and glib/glibconfig.h.win32.in
Since the Visual Studio projects are dropped, the pre-configured
config.h.win32.in and glib/glibconfig.h.win32.in are no longer needed.
2018-06-06 23:54:13 +08:00
Chun-wei Fan
f658e94e65 build: Drop Visual Studio projects
In master, it is already possible to build GLib using Visual Studio
using Meson[1] for some time, so we should focus on maintaining only the
Meson build files for building GLib with Visual Studio.

[1]: There are caveats when building with Visual Studio 2008, namely
     that one needs to use the mt command to embed the manifests that
     are generated with the .exe/DLLs, for all builds, and that in the
     case where the compilation hangs on Visual Studio 2008 x64, as a
     workaround, should stop the build by terminating all cl.exe tasks
     and change the compiler optimization flag from /O2 (full speed) to
     /O1 (optimize for size), due to compiler optimization issues.
2018-06-06 23:54:13 +08:00
Will Thompson
0f7c196c21
g_clear_handle_id: don't accept NULL clear_func
Fixes #1401.
2018-06-04 13:11:49 +01:00
Philip Withnall
e1e8002998 garray: Optimise over-allocations with g_array_insert_vals()
When over-allocating by inserting values off the end of an array, maybe
expand the array once, rather than twice (once for setting the size and
once for appending the values).

Suggestion by Peter Bloomfield (@peterb) as a follow-up to #1374.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-04 11:45:48 +01:00
Philip Withnall
80243e65b6 tests: Expand GArray test coverage to cover all construction forms
Previously, there was very little coverage of GArray behaviour with
either of the zero_terminated or clear_ arguments to g_array_new() set
to TRUE.

Parameterise the tests and exhaustively expand the coverage to cover all
possible GArray configurations.

This was made possible by the online code coverage report for GLib which
we now have:
https://gnome.pages.gitlab.gnome.org/glib/coverage/glib/garray.c.gcov.html.

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

https://bugzilla.gnome.org/show_bug.cgi?id=795975
2018-06-04 11:11:26 +01:00
Philip Withnall
89f45e96b2 garray: Allow over-allocation in g_array_insert_vals()
Previously, g_array_insert_vals() would crash if called with an index
off the end of the array. This is inconsistent with the behaviour of
other methods (like g_array_set_size()), which will expand the array as
necessary.

Modify g_array_insert_vals() to expand the array as necessary. New array
elements will be cleared to zero if the GArray was constructed with
(clear_ == TRUE).

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

https://bugzilla.gnome.org/show_bug.cgi?id=795975
2018-06-04 11:11:26 +01:00