Commit Graph

18625 Commits

Author SHA1 Message Date
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
Matej Urbančič
aa6721f1ee Updated Slovenian translation 2018-07-11 21:12:00 +02:00
Emmanuele Bassi
bdf70242b7 Merge branch '640-appinfo-skip-display' into 'master'
tests: Fix skipping of appinfo tests when DISPLAY is unset

Closes #640

See merge request GNOME/glib!171
2018-07-11 18:08:48 +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
3890f7f5cb tests: Fix skipping of appinfo tests when DISPLAY is unset
Use g_test_skip() so that the TAP output is correct for the tests,
rather than printing using g_printerr().

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

https://gitlab.gnome.org/GNOME/glib/issues/640
2018-07-11 15:58:48 +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
Iain Lane
747c2f5720 gobject: Make g_clear_object take a non-volatile GObject **
The implementation is silently discarding this anyway, and
g_object_unref() is using atomic operations. So this should be safe.

Having this here triggers -Wdiscarded-qualifiers when g_clear_pointer()
is fixed to use __typeof__().
2018-07-11 10:52:53 +01:00
Emmanuele Bassi
ad3947c42e Merge branch '927-resource-path-fix' into 'master'
gresource: Fix potential array overflow if using empty paths

Closes #927

See merge request GNOME/glib!150
2018-07-11 09:24:03 +00: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
Iain Lane
40b306b81c Merge branch '340-gdbus-fixme' into 'master'
Remove an outdated TODO comment

Closes #340

See merge request GNOME/glib!168
2018-07-10 21:28:20 +00:00
Emmanuele Bassi
51065370a0 Merge branch '1041-atomic-bad-function-cast' into 'master'
Allow g_atomic_pointer_get() to be used by projects which enable -Wbad-function-cast

Closes #1041

See merge request GNOME/glib!166
2018-07-10 21:24:54 +00:00
Philip Withnall
034bbfd873 gdbusconnection: Drop an outdated TODO comment
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/340
2018-07-10 19:16:35 +02: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
Philip Withnall
4a53ed2073 Merge branch 'wip/hughsie/g_ref_string_new_len' into 'master'
Add a g_ref_string_new_len() to allow creating from non-NUL byte arrays

See merge request GNOME/glib!158
2018-07-09 17:30:12 +00: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
Philip Withnall
4deb94f067 Merge branch '1201-inotify-linking' into 'master'
Resolve "Linking failure on midipix with slibtool"

Closes #1201

See merge request GNOME/glib!157
2018-07-09 11:16:29 +00:00
Emmanuele Bassi
2585099a5d Merge branch 'refcount-box' into 'master'
Reference counted data allocations

See merge request GNOME/glib!92
2018-07-09 09:39:30 +00:00
Philip Withnall
9d6a69b73e gio: Link inotify file monitor to GLib and GObject
Apparently this is needed for building PE libraries. It makes no
difference on Linux, where linking of the GLib symbols in the inotify
file monitor code is done lazily.

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

https://gitlab.gnome.org/GNOME/glib/issues/1201
2018-07-09 10:38:04 +01: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
884c4f4eb6 ci: Add allow_failure: true to FreeBSD runner
The FreeBSD runner is not stable yet. See
https://gitlab.gnome.org/Infrastructure/GitLab/issues/286.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-07-09 09:53:33 +01:00
Daniel Mustieles
419d4e610d Updated Spanish translation 2018-07-09 08:49:29 +02:00
Philip Withnall
f9589218dc Merge branch 'pcre-meson-dependency' into 'master'
meson: Add libpcre dependency version, as in configure.ac

See merge request GNOME/glib!155
2018-07-08 18:43:39 +00:00
Philip Withnall
6fea3289db Merge branch 'wip/lantw/ci-on-freebsd' into 'master'
Fix tests and add CI for FreeBSD

See merge request GNOME/glib!57
2018-07-08 18:41:30 +00:00
Philip Withnall
4256d99c3d meson: Add libpcre dependency version, as in configure.ac
Prompted by https://gitlab.gnome.org/GNOME/glib/merge_requests/148.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-07-08 14:34:53 +01:00