Commit Graph

21762 Commits

Author SHA1 Message Date
Philip Withnall
26c433d26c tests: Speed up the file test and make it more reliable
Sometimes this test was timing out due to the file monitor notifications
taking longer than the arbitrary 2s delay before ending the test and
checking its results at the end of `iclosed_cb()`.

Avoid that timing-dependence by ending the test when the expected file
monitor notifications are seen, or after a 10s timeout (if so, the test
is failed).

This makes the test run 4× faster in the normal case, as it’s no longer
waiting for a timeout to elapse if the file monitor notifications come
in sooner.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-22 11:05:27 +01:00
Philip Withnall
43969bf41a tests: Port file test to use g_assert_*() rather than g_assert()
g_assert() can be compiled out with G_DISABLE_ASSERT, which renders the
test rather useless.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-22 11:04:34 +01:00
Philip Withnall
31099d97eb Merge branch 'fix-2107-windows-gpoll-stall' into 'master'
win32 gpoll: Fix wait for at least one thread to return

Closes #2107

See merge request GNOME/glib!1504
2020-05-22 08:11:00 +00:00
Philip Withnall
8f291487fe Merge branch 'lcopyfail' into 'master'
gobject: Handle runtime checks as such

See merge request GNOME/glib!1505
2020-05-20 16:49:17 +00:00
Edward Hervey
898baa07b1 gobject: Handle runtime checks as such
The various `g_strdup_printf()` returns values in the implementations of GValue
lcopy_func are runtime checks which could be disabled if one wants and therefore
should be handled as such with g_return_val_if_fail()
2020-05-20 17:37:46 +02:00
majordaw
26991b6093 win32 gpoll: Fix wait for at least one thread to return
When timeout grater than 0 in g_poll function, the WaitForMultipleObjects
call will wait for all the threads to return, but when only one thread
got an event the others will sleep until the timeout elapses, and causes
a stall. Triggering the stop event in g_poll in this case is useless as
it is triggered when all the threads where already signaled or timed-out.

Closes: https://gitlab.gnome.org/GNOME/glib/issues/2107
2020-05-20 15:32:47 +02:00
Sebastian Dröge
e816e9c86f Merge branch 'docs-fix' into 'master'
docs: Add indexes for symbols added in 2.66

See merge request GNOME/glib!1503
2020-05-20 12:13:29 +00:00
Philip Withnall
9f421dd678 docs: Add indexes for symbols added in 2.66
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-20 12:20:28 +01:00
Sebastian Dröge
e992b9978e Merge branch 'value-interned' into 'master'
GValue: Add interned string support

Closes #2109

See merge request GNOME/glib!1497
2020-05-20 08:25:40 +00:00
Sebastian Dröge
1d61c97761 Merge branch '1323-aarch64-mem-barrier' into 'master'
gthread: Use C11-style memory consistency to speed up g_once()

Closes #1323

See merge request GNOME/glib!1364
2020-05-19 17:22:41 +00:00
Edward Hervey
73d7f35ce7 gbinding: Use new g_value_set_interned_string() API for performance
The property strings are interned already, so this potentially allows for faster
comparisons. The property strings were already not copied, as they were tagged
as static.
2020-05-19 17:52:55 +02:00
Edward Hervey
1a95ce84ed GValue: Add interned string support
This adds support to be able to explicitely stored interned strings into
G_TYPE_STRING GValue.

This is useful for cases where the user:
* *knows* the string to be stored in the GValue is canonical
* Wants to know whther the string stored is canonical

This allows:
* zero-cost GValue copy (the content is guaranteed to be unique and exist
  throughout the process life)
* zero-cost string equality checks (if both string GValue are interned, you just
  need to check the pointers for equality or not, instead of doing a strcmp).

Fixes #2109
2020-05-19 17:52:55 +02:00
Edward Hervey
c964749de6 test: Add string GValue tests
Tests creation, duplication, ownership and copies
2020-05-19 17:52:55 +02:00
Edward Hervey
e3efbd30a2 gvalue: Static strings should not be copied
When doing copies of GValue backed by static strings, the contents should not be copied
2020-05-19 17:52:55 +02:00
Philip Withnall
c1d7097d0a build: Drop unused G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
See the previous commit.

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

Helps: #1323
2020-05-19 16:20:31 +01:00
Philip Withnall
e52fb6b1d3 gthread: Use C11-style memory consistency to speed up g_once()
The g_once() function exists to call a callback function exactly once,
and to block multiple contending threads on its completion, then to
return its return value to all of them (so they all see the same value).

The full implementation of g_once() (in g_once_impl()) uses a mutex and
condition variable to achieve this, and is needed in the contended case,
where multiple threads need to be blocked on completion of the callback.

However, most of the times that g_once() is called, the callback will
already have been called, and it just needs to establish that it has
been called and to return the stored return value.

Previously, a fast path was used if we knew that memory barriers were
not needed on the current architecture to safely access two dependent
global variables in the presence of multi-threaded access. This is true
of all sequentially consistent architectures.

Checking whether we could use this fast path (if
`G_ATOMIC_OP_MEMORY_BARRIER_NEEDED` was *not* defined) was a bit of a
pain, though, as it required GLib to know the memory consistency model
of every architecture. This kind of knowledge is traditionally a
compiler’s domain.

So, simplify the fast path by using the compiler-provided atomic
intrinsics, and acquire-release memory consistency semantics, if they
are available. If they’re not available, fall back to always locking as
before.

We definitely need to use `__ATOMIC_ACQUIRE` in the macro implementation
of g_once(). We don’t actually need to make the `__ATOMIC_RELEASE`
changes in `gthread.c` though, since locking and unlocking a mutex
guarantees to insert a full compiler and hardware memory barrier
(enforcing sequential consistency). So the `__ATOMIC_RELEASE` changes
are only in there to make it obvious what stores are logically meant to
match up with the `__ATOMIC_ACQUIRE` loads in `gthread.h`.

Notably, only the second store (and the first load) has to be atomic.
i.e. When storing `once->retval` and `once->status`, the first store is
normal and the second is atomic. This is because the writes have a
happens-before relationship, and all (atomic or non-atomic) writes
which happen-before an atomic store/release are visible in the thread
doing an atomic load/acquire on the same atomic variable, once that load
is complete.

References:
 * https://preshing.com/20120913/acquire-and-release-semantics/
 * https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/_005f_005fatomic-Builtins.html
 * https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync
 * https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering

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

Fixes: #1323
2020-05-19 16:17:39 +01:00
Sebastian Dröge
e4c3af9d4e Merge branch '602-introspect-thread' into 'master'
gthread: Add introspection annotations

Closes #602

See merge request GNOME/glib!1499
2020-05-19 15:15:00 +00:00
Philip Withnall
bfd8f8cbaf tests: Add multi-threaded test for g_once()
There were multi-threaded tests for g_once_init_{enter,leave}(), but not
for g_once(). Add one which tests multi-threaded contention for entering
and retrieving the value of the `GOnce`.

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

Helps: #1323
2020-05-19 16:06:07 +01:00
Philip Withnall
596fa49aa0 tests: Tidy up test naming in glib/tests/once.c
Make it a little clearer. This introduces no functional changes.

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

Helps: #1323
2020-05-19 16:06:07 +01:00
Sebastian Dröge
536e32c5a8 Merge branch '176-malloc-docs' into 'master'
gmem: Improve documentation to clarify abort-on-alloc-failure

Closes #176

See merge request GNOME/glib!1500
2020-05-19 14:41:27 +00:00
Philip Withnall
445aa65e90 gmem: Improve documentation to clarify abort-on-alloc-failure
Clarify that it applies to everything.

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

Fixes: #176
2020-05-19 15:12:16 +01:00
Philip Withnall
1cb2db8515 gthread: Add introspection annotations
It’s not expected that bindings will use `GThread` over their own
threading APIs (in fact that would generally be a bad idea, since
threads benefit from being integrated into language control flow
structures), but it can’t hurt to have the annotations right for
documentation purposes if nothing else.

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

Fixes: #602
2020-05-19 14:52:17 +01:00
Philip Withnall
81ee85c793 Merge branch 'th/g-ptr-array-new' into 'master'
array: add internal ptr_array_new() helper for creating GPtrArray

See merge request GNOME/glib!1498
2020-05-18 10:28:25 +00:00
Cheng-Chia Tseng
b86d6fee66 Update Chinese (Taiwan) translation 2020-05-17 17:09:06 +00:00
Emin Tufan Çetin
20fb5bf868 Update Turkish translation 2020-05-16 11:58:36 +00:00
Thomas Haller
1efa966b6f array: add internal ptr_array_new() helper for creating GPtrArray
Unify the creation of GPtrArray.

Maybe we will add yet another constructor for creating %NULL terminated
arrays. Unify the constructors by adding an internal helper method.

The alternative instead of adding a ptr_array_new() helper, would be to
let everybody call g_ptr_array_full(). For no strong reasons, choose
this approach because the compiler is more eager to inline the static
helper as it would inlining g_ptr_array_full().
2020-05-15 17:47:11 +02:00
Sebastian Dröge
f6d26ba772 Merge branch 'fix-1487-reversion' into 'master'
Fix GLIB_UNAVAILABLE_STATIC_INLINE declaration

See merge request GNOME/glib!1496
2020-05-15 13:10:03 +00:00
Philip Withnall
4364c51722 gmacros: Add missing GLIB_UNAVAILABLE_STATIC_INLINE declaration
This fixes building against GLib with
`GLIB_DISABLE_DEPRECATION_WARNINGS` defined.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
See: !1487
2020-05-15 12:00:03 +01:00
Philip Withnall
0fc7f409f6 Revert "Revert "glib: annotate static inline functions with G_AVAILABLE-type macros""
This reverts commit c0146be3a4.

The revert was originally added because the original change broke
gnome-build-meta. Now that the problem has been diagnosed, the original
commit can be fixed — see the commit which follows this one.

See: !1487
2020-05-15 11:59:06 +01:00
Philip Withnall
85f8efae0f Merge branch 'aleksm/mkenums-since' into 'master'
glib-mkenums: allow optional 'since' tag

See merge request GNOME/glib!1492
2020-05-14 16:10:33 +00:00
Philip Withnall
01fbeb601b Merge branch 'assert-no-errno' into 'master'
gtestutils: Add a new g_assert_no_errno() test macro

See merge request GNOME/glib!1204
2020-05-14 16:09:40 +00:00
Sebastian Dröge
12fbb286ae Merge branch 'fix-cpu-docker' into 'master'
ci: Update Android Docker image for aarch64 CPU naming change

See merge request GNOME/glib!1402
2020-05-14 15:12:48 +00:00
Sebastian Dröge
bc2bfdfa43 Merge branch '2082-get-rid-of-am-pm' into 'master'
gdatetime: Document that specific AM/PM formatting is discouraged

Closes #2082

See merge request GNOME/glib!1445
2020-05-14 15:07:12 +00:00
Aleksander Morgado
ec6056e3ab glib-mkenums: allow optional 'since' tag
The glib-mkenums program allows generating code to handle enums/flags
with very different purposes. One of its purposes could be generating
per-enum/flag methods to be exposed in a library API, and while doing
that, it would be nice to have a way to specify in which API version
the enum/flag was introduced, so that the same version could be shown
in the generated API methods.

E.g. From the following code:

    /**
     * QmiWmsMessageProtocol:
     * @QMI_WMS_MESSAGE_PROTOCOL_CDMA: CDMA.
     * @QMI_WMS_MESSAGE_PROTOCOL_WCDMA: WCDMA.
     *
     * Type of message protocol.
     *
     * Since: 1.0
     */
    typedef enum { /*< since=1.0 >*/
        QMI_WMS_MESSAGE_PROTOCOL_CDMA  = 0x00,
        QMI_WMS_MESSAGE_PROTOCOL_WCDMA = 0x01
    } QmiWmsMessageProtocol;

The template would allow us to generate a method documented like this,
including the Since tag with the value given in the mkenums 'since' tag.

    /**
     * qmi_wms_message_protocol_get_string:
     * @val: a QmiWmsMessageProtocol.
     *
     * Gets the nickname string for the #QmiWmsMessageProtocol specified at @val.
     *
     * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value.
     * Since: 1.0
     */
    const gchar *qmi_wms_message_protocol_get_string (QmiWmsMessageProtocol val);

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
2020-05-14 17:00:54 +02:00
Aleksander Morgado
4d1132a945 docs,glib-mkenums: setup lists for enum/value trigraph extensions
Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
2020-05-14 17:00:46 +02:00
Emmanuele Bassi
700be9f22d Merge branch 'meson-fix' into 'master'
meson: Remove stray ] in O_DIRECTORY check

See merge request GNOME/glib!1493
2020-05-14 14:02:20 +00:00
Chris Packham
a714484208 meson: Remove stray ], in O_DIRECTORY check
A stray ], was leftover from the autotools -> meson conversion. Remove
it.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
2020-05-14 10:18:39 +12:00
Michael Catanzaro
c0146be3a4 Revert "glib: annotate static inline functions with G_AVAILABLE-type macros"
This reverts commit 5050298749
2020-05-12 21:28:52 +00:00
Philip Withnall
a6b1afca6a Merge branch 'zbrown/datetime-annotations' into 'master'
gdatetime: update annotations

See merge request GNOME/glib!1491
2020-05-12 12:53:14 +00:00
Philip Withnall
ef1b057977 Merge branch 'static-inline-available' into 'master'
glib: annotate static inline functions with G_AVAILABLE-type macros

See merge request GNOME/glib!1487
2020-05-12 12:47:46 +00:00
Zander Brown
afaa2e31e6
gdatetime: add preconditons to public methods
Should make it easier to debug than segfaulting in from_instant
2020-05-12 13:02:20 +01:00
Zander Brown
86a0b5530d
gdatetime: update annotations
Every constructor and just about every method can and will (silently) return NULL, add
annotations to reflect this
2020-05-12 13:02:19 +01:00
Simon Marchi
5050298749 glib: annotate static inline functions with G_AVAILABLE-type macros
The public functions exposed as static inlines currently don't have
annotations to describe when they were introduced.  This means that
compiling this file:

    #include <glib.h>

    void foo (void)
    {
      g_rec_mutex_locker_new (NULL);
    }

with:

    gcc -c test.c \
      -I/tmp/glib/include/glib-2.0 \
      -I/tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \
      -Werror \
      -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 \
      -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28

will not produce any error message, despite using
`g_rec_mutex_locker_new`, a function that was introduced after 2.28.

This patch adds some annotations to all the publicly exposed static
inline functions I could find.

I could not use the existing G_AVAILABLE* macros, because they may
expand to `extern`.  This would then clash with the `static` keyword and
produce:

    ../glib/gthread.h:397:1: error: multiple storage classes in declaration specifiers
      397 | static inline GRecMutexLocker *
          | ^~~~~~

So I opted for adding a new set of macros,
GLIB_AVAILABLE_STATIC_INLINE_IN_2_XY.

With this patch applied, the example from above produces the expected
warning:

    test.c: In function ‘foo’:
    test.c:5:3: error: ‘g_rec_mutex_locker_new’ is deprecated: Not available before 2.60 [-Werror=deprecated-declarations]
        5 |   g_rec_mutex_locker_new (NULL);
          |   ^~~~~~~~~~~~~~~~~~~~~~
    In file included from /tmp/glib/include/glib-2.0/glib/gasyncqueue.h:32,
                     from /tmp/glib/include/glib-2.0/glib.h:32,
                     from test.c:1:
    /tmp/glib/include/glib-2.0/glib/gthread.h:398:1: note: declared here
      398 | g_rec_mutex_locker_new (GRecMutex *rec_mutex)
          | ^~~~~~~~~~~~~~~~~~~~~~
2020-05-12 12:42:50 +01:00
Philip Withnall
06dc61ad6c Merge branch 'clang-win-stpcpy' into 'master'
Don't misdetect stpcpy on windows platforms on clang

See merge request GNOME/glib!1439
2020-05-12 11:39:44 +00:00
Martin Storsjö
1b94bfbd72 meson: Don't misdetect stpcpy on windows platforms on clang
See https://github.com/mesonbuild/meson/issues/3672 and
https://github.com/mesonbuild/meson/issues/5628 for explanations
of cases where meson misdetects functions due to clang builtins (that
always are available, regardless of whether the platform actually
provides them).

The same also happens on GCC 10, which added support for __has_builtin.
2020-05-11 20:23:43 +03:00
Michael Catanzaro
493b01c305 Merge branch 'option-context-translations' into 'master'
goption: Treat an empty option context parameter string as NULL

See merge request GNOME/glib!1469
2020-05-08 20:26:33 +00:00
Philip Withnall
9363fe4695 Merge branch 'wip/smcv/apple-xucred' into 'master'
gio: add gcredential support for macOS

Closes #507

See merge request GNOME/glib!1416
2020-05-07 14:05:57 +00:00
Dr. Michael Lauer
ec2f60a008 gio: add gcredential support for macOS
[smcv: Apply my review feedback from
<https://bugzilla.gnome.org/show_bug.cgi?id=668866>]

Co-authored-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.gnome.org/GNOME/glib/issues/507
2020-05-07 14:19:16 +01:00
Simon McVittie
05cb229082 GCredentials: Add the concept of credentials that lack the process ID
struct xucred on macOS doesn't have the process ID, only the user ID
and groups.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-05-07 14:19:16 +01:00
Philip Withnall
a9a7aa05dc Merge branch 'wip/hadess/update-fedora-ci' into 'master'
Update Fedora CI

See merge request GNOME/glib!1464
2020-05-07 11:42:08 +00:00