Commit Graph

30853 Commits

Author SHA1 Message Date
Philip Withnall
133ade7244 Merge branch 'ebassi/gi-docgen-wrap-update' into 'main'
Update the wrap file for gi-docgen

See merge request GNOME/glib!3816
2024-09-25 16:45:45 +00:00
Philip Withnall
efab4c1c71
build: Bump the gi-docgen dependency to 2024.1
This gives us an updated enumeration template and link validation,
amongst other things.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-25 17:27:46 +01:00
Emmanuele Bassi
e6d0229b22 subprojects: Update the wrap file for gi-docgen
Use the [provide] section to override the binary name, and track the
main development branch, like GTK does, so we get warnings and a
consistent output.
2024-09-25 17:24:56 +01:00
Philip Withnall
428942d626 Merge branch 'wraps' into 'main'
subprojects: Update pcre2 to 10.44

See merge request GNOME/glib!4268
2024-09-25 16:22:53 +00:00
Philip Withnall
8b8b8a5a5e
ci: Bump CI image versions to cache new version of PCRE
As per the previous commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-25 17:06:10 +01:00
Benjamin Gilbert
47f11d20d9 subprojects: Update pcre2 to 10.44
Bug fixes.
2024-09-25 17:06:04 +01:00
Philip Withnall
0ad601ef38 Merge branch 'c_std' into 'main'
build: switch back to c_std=gnu99 pending ObjC fix

See merge request GNOME/glib!4305
2024-09-25 15:22:03 +00:00
Philip Withnall
fd9c00179f Merge branch 'wip/chergert/gvariant-use-proper-macros-conditions' into 'main'
Fix incorrect use of assert/debug/check macros

See merge request GNOME/glib!4292
2024-09-25 15:06:10 +00:00
Benjamin Gilbert
23009aadc6 build: switch back to c_std=gnu99 pending ObjC fix
It's better to warn by default on MSVC (which we were already doing before
we bumped to 1.4.0) than to fail by default on macOS.

Fixes: 51e3e7d9ae ("build: Bump Meson dependency to 1.4.0")
2024-09-25 07:45:06 -07:00
Philip Withnall
f2ca182ab4 Merge branch 'wip/chergert/fix-gvariant-spec' into 'main'
docs/gvariant: fix a(si) example in specification

Closes #3478

See merge request GNOME/glib!4289
2024-09-25 14:39:05 +00:00
Philip Withnall
267342420f Merge branch 'wip/chergert/fix-ganalyzer-use' into 'main'
glib/gvariant: Fix check for G_ANALYZER_ANALYZING

Closes #3480

See merge request GNOME/glib!4291
2024-09-25 13:43:02 +00:00
Philip Withnall
04e45e3cef Merge branch 'wip/chergert/gvariant-transfer-gbyte-ownership' into 'main'
glib/gvariant: Avoid extraneous GBytes ref counting

See merge request GNOME/glib!4299
2024-09-25 13:42:57 +00:00
Philip Withnall
2691c5e24e
gdbusdaemon: Fix check for G_ANALYZER_ANALYZING
As with the previous commit, this is _always_ defined in `gmacros.h`
and therefore the `#ifndef` will always be 0 even if disabled.
Just use `#if` instead.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-25 14:30:48 +01:00
Philip Withnall
5ac765689c Merge branch 'wip/chergert/g_variant_ref_sink-perf' into 'main'
glib/gvariant: skip bitlock for g_variant_ref_sink()

See merge request GNOME/glib!4302
2024-09-25 13:21:56 +00:00
Philip Withnall
765eea0a78 Merge branch 'wip/chergert/gvarianttype-proper-const' into 'main'
gvarianttype: mark const functions as such

See merge request GNOME/glib!4294
2024-09-25 13:11:11 +00:00
Philip Withnall
e071e1bfc0 Merge branch 'wip/chergert/avoid-malloc-in-format-string-validation' into 'main'
gvariant: Avoid malloc/free in valid_format_string()

See merge request GNOME/glib!4295
2024-09-25 13:10:34 +00:00
Philip Withnall
5d40bc448e Merge branch 'wip/chergert/g_variant_type_is_subtype_of-fastpath' into 'main'
glib/gvarianttype: g_variant_type_is_subtype_of() fastpath

See merge request GNOME/glib!4297
2024-09-25 13:08:52 +00:00
Philip Withnall
4596bd819d Merge branch 'wip/chergert/gvariantbuilder-avoid-g_renew-for-known-children-length' into 'main'
glib/gvariant: avoid g_renew() for definite tuples

See merge request GNOME/glib!4298
2024-09-25 13:03:22 +00:00
Christian Hergert
9a380ee918 glib/gvariant: Avoid extraneous GBytes ref counting
Right now we create a bunch of GBytes which then get their reference count
incremented and immediately decremented. This causes quite a bit of
disruption for cacheline re-use.

Instead, this change creates an internal helper to transfer ownership of
GBytes to the new GVariant directly.

Surprisingly, this reduced wallclock time by about 6% for a contrived
benchmark of building "as" variant with GVariantBuilder.
2024-09-25 13:09:17 +01:00
Philip Withnall
842c828535 Merge branch 'wip/chergert/use-utf8-validate-for-strlen' into 'main'
glib/gvariant: use g_utf8_validate() for strlen

See merge request GNOME/glib!4296
2024-09-25 12:00:26 +00:00
Philip Withnall
4a72791181
tests: Add tests for UTF-8 checks for g_variant_new_string()
Brings the test coverage from the previous commit back up to 100% of
lines of those functions.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-25 12:24:22 +01:00
Philip Withnall
67d5c59c5a Merge branch 'wip/chergert/gbytes-avoid-alloc' into 'main'
glib/gbytes: save small byte buffers inline

See merge request GNOME/glib!4290
2024-09-25 10:49:20 +00:00
Christian Hergert
1e3b010af8 glib/gbytes: save small byte buffers inline
When dealing with small allocations it can save considerable cycles to
do a single allocation for both the GBytes and the data by tacking it
onto the end of the GBytes.

Care is taken to preserve the glibc expectation of 2*sizeof(void*)
alignment of allocations at the expense of some padding bytes.

The degenerate case here is when you want to steal the bytes afterwards
but that amounts to the same overhead as the status-quo.

Where this can help considerably is in GVariant building such as
g_variant_new_int32() which allocates for the GVariant, the GBytes, and
the int32 within the GBytes.

In a simple benchmark of using GVariantBuilder to create "(ii)" variants
this saved about 10% in wallclock time.
2024-09-25 10:49:19 +00:00
Philip Withnall
0d1719868d Merge branch 'girepository-gcc48' into 'main'
girepository: Make _blob_is_registered_type static inline

See merge request GNOME/glib!4288
2024-09-25 10:42:53 +00:00
Olivier Blin
190f9249cd girepository: Make _blob_is_registered_type static inline
This follows the usage in the glib codebase and recommendations at
main/docs/toolchain-requirements.md

It also fixes a build warning with ancient gcc 4.8:
../girepository/gitypelib-internal.h:202:1: warning:
no previous prototype for ‘_blob_is_registered_type’ [-Wmissing-prototypes]
2024-09-25 10:45:05 +02:00
Christian Hergert
3566aeb079 glib/gvariant: skip bitlock for g_variant_ref_sink()
In almost all cases, the variant is sunk shortly after creation and
certainly before other threads get a view of it.

This skips the bitlock for STATE_FLOATING, which is also done in
g_variant_take_ref(). We can do this because STATE_FLOATING may only
be set up-front, never after being cleared.

That allows us to do a relaxed read of the value once (which if it is
zero means no additional atomics beyond our ref count increment) as well
as a single atomic if we do in fact steal the floating reference.

Without any other GVariant performance changes, this is in the 2% range
of benchmarking a tight loop using GVariantBuilder. However, after the
rest of them are applied, the percentage is greater due to reduced
runtime overhead and lands in the 4.5% range.
2024-09-24 18:24:55 -07:00
Christian Hergert
bd0f462729 glib/gvariant: avoid g_renew() for definite tuples
If you have a definite-tuple type such as (iiii) then the number of
children that are allocated will match the offset when a GVariantBuilder
has completed.

That means we can avoid an expensive call into the allocator which is
normally done to shrink memory use by releasing it back to the allocator.

This saves about 5% of wallclock time when building such variants in a
tight loop.
2024-09-24 11:23:54 -07:00
Christian Hergert
7d4ea04ee2 glib/gvarianttype: g_variant_type_is_subtype_of() fastpath
This adds a fastpath for the extremely common case of checking if a
GVariant type is a subtype of itself _and_ a definite basic type. For
example, checking 'i' against 'i' or 's' against 's'.

In a loop using GVariantBuilder this can cut the cost of this function
alone in half on profiles from 3.3% of samples to 1.7% of samples.
2024-09-24 11:13:56 -07:00
Christian Hergert
db77480d97 glib/gvariant: use g_utf8_validate() for strlen
We can get the length of the string if we provide an out argument to
g_utf8_validate(). This avoids an extra strlen() when creating GVariant
for UTF-8 strings.

This is good for nearly 7% reduction of CPU samples when building
heavily string-based GVariant using GVariantBuilder as a benchmark.
2024-09-24 11:06:15 -07:00
Christian Hergert
7e362048a3 gvariant: Avoid malloc/free in valid_format_string()
Any extremely common use-case of valid_format_string() is validation
when using GVariantBuilder. The optimal-case there is that there is
no programming error and thus the fast path should match.

This creates a fast path for that case without substantial change to the
GVariant type-checking case by checking for a non-NULL GVariant. It then
proceeds to hoist the actual scan directly without type allocation.

Locally this single change reduces wallclock time in a single-threaded
benchmark using GVariantBuilder by 17%.
2024-09-24 11:02:22 -07:00
Christian Hergert
49bfa7b9cf gvarianttype: mark const functions as such
These functions only rely on their input parameter and no globals, thus
are candidates for sub-expression elimination.
2024-09-24 10:59:20 -07:00
Christian Hergert
049149c4b7 glib/gvariant: Fix check for G_ANALYZER_ANALYZING
This is _always_ defined in gmacros.h and therefore the #ifdef will always
be 1 even if were disabled. Just #if instead.

Closes: #3480
2024-09-24 09:34:21 -07:00
Christian Hergert
786a5d364c glib/gvarianttype: use G_DISABLE_CAST_CHECKS
Previously, G_VARIANT_TYPE() would "cast check" the type string unless
G_DISABLE_CHECKS was set. We very much don't want people to ever set
G_DISABLE_CHECKS but it is extremely normal to turn of cast-checks using
G_DISASABLE_CAST_CHECKS in stable releases.

This allows disabling the expensive type checking without catastrophically
disabling g_return_if_fail() macros.
2024-09-24 09:27:25 -07:00
Christian Hergert
9eb9df2396 glib/gvarianttypeinfo: use G_ENABLE_DEBUG not !G_DISABLE_ASSERT
Distributions are directed to disable G_ENABLE_DEBUG in stable builds.
Many do not currently disable assertion checks with G_DISABLE_ASSERT.

However this code is very much meant for debugging implementation details
rather than runtime validation. Use G_ENABLE_DEBUG instead of
!G_DISABLE_ASSERT to get the intended behavior.
2024-09-24 09:27:25 -07:00
Christian Hergert
ff00e9c2ed docs/gvariant: fix a(si) example in specification
This has a trailing 0x15 on it when you create it with GVariant and the
specification should match.

Closes: #3478
2024-09-24 09:22:52 -07:00
Philip Withnall
84b6f747cb Merge branch 'socks4a-buffer-overflow' into 'main'
gsocks4aproxy: Fix a single byte buffer overflow in connect messages

Closes #3461

See merge request GNOME/glib!4281
2024-09-19 20:21:05 +00:00
Michael Catanzaro
25833cefda gsocks4aproxy: Fix a single byte buffer overflow in connect messages
`SOCKS4_CONN_MSG_LEN` failed to account for the length of the final nul
byte in the connect message, which is an addition in SOCKSv4a vs
SOCKSv4.

This means that the buffer for building and transmitting the connect
message could be overflowed if the username and hostname are both
`SOCKS4_MAX_LEN` (255) bytes long.

Proxy configurations are normally statically configured, so the username
is very unlikely to be near its maximum length, and hence this overflow
is unlikely to be triggered in practice.

(Commit message by Philip Withnall, diagnosis and fix by Michael
Catanzaro.)

Fixes: #3461
2024-09-19 21:08:15 +01:00
Michael Catanzaro
60aa29df19 Merge branch 'mcatanzaro/#3469' into 'main'
gvariant-parser: add assert to ensure we don't write too far

Closes #3469

See merge request GNOME/glib!4280
2024-09-19 17:38:40 +00:00
Philip Withnall
2842e4a86f
gvariant-parser: Assert that pattern lengths don’t overflow
I can’t see it being possible for this to be hit in practice, as it
would require two very long GVariant text format inputs, which would
probably hit input limits earlier on somewhere else.

But in order to avoid a silent integer overflow, let’s check that the
addition won’t overflow before going ahead with it.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3469
2024-09-19 17:49:10 +01:00
Philip Withnall
785b61cfcb
gvariant-parser: Add additional buffer byte for nul terminator
In `pattern_coalesce()`.

I am fairly sure this byte is never needed, as the most extreme case of
`max (strlen (left), strlen (right)` vs `strlen (left) + strlen (right)`
I can think of still gives 1 byte left in the buffer (without the need
for this commit).

However, the proof we have of how much space is needed in the buffer
only goes far enough to show that the number of bytes needed before the
nul terminator is at most `strlen (left) + strlen (right)`. That means
we still technically need to add an additional byte for the nul
terminator.

The need for this could be eliminated by coming up with a stronger proof
to show that the number of bytes needed is strictly less than `strlen
(left) + strlen (right)`, but I can’t do that, and adding one byte is
easy to do. Type strings are short and we’re nowhere near making a large
allocation here.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3469
2024-09-19 17:44:28 +01:00
Philip Withnall
c7e3512902
tests: Add some additional pattern_coalesce() tests
The first of these tests is to cover the extreme case where the number
of bytes written out by `pattern_coalesce()` is as close to `strlen
(left) + strlen (right)` as we can manage, due to both inputs being
really small and hence `max (strlen (left), strlen (right))` being only
1 less than `strlen (left) + strlen (right)`, which is as close as we
can get to triggering an off-by-one error.

The second of these tests is an attempt to encode the case used in the
proof for correctness of `pattern_coalesce()` not overflowing its buffer
bounds: `(*(iii)) + ((iii)*) = ((iii)(iii))`. I don’t think it’s
actually possible to hit that case, as it’s not possible to generate a
plain `*` in either of the input patterns. `Ma*` is the best we can
manage in practice. See
https://gitlab.gnome.org/GNOME/glib/-/issues/3469#note_2226901 for
reasoning.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3469
2024-09-19 17:40:45 +01:00
Philip Withnall
1cb682b320
tests: Fix a minor typo in a comment in gvariant tests
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-09-19 17:40:24 +01:00
Philip Withnall
3d5ada2689
gvariant-parser: Add a proof for pattern_coalesce()’s safety
This proof backs up the already-present assertion that “the length of
the output is loosely bounded by the sum of the input lengths”.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3469
2024-09-19 16:35:27 +01:00
Michael Catanzaro
7f4300c5da gvariant-parser: add assert to ensure we don't write too far
This function is complicated and it's hard to assess whether it is
correct or not, so let's add an assert just to be sure.

Notably, when writing this I initially had an off-by-one error in my
assert, causing the assertion to actually fire when running the unit
tests. So we know it's definitely possible for the function to use the
entirety of the buffer. The upper bound is not loose, and writing one
additional byte would be a security bug.

Note my assertion possibly doesn't protect against security issues
because it will be hit after the bad write rather than before.

Fixes #3469
2024-09-19 09:59:13 -05:00
Philip Withnall
1adc303f47 Merge branch 'inotify-kqueue' into 'main'
Introduce a new GFileMonitor backend: libinotify-kqueue

See merge request GNOME/glib!3657
2024-09-19 10:13:33 +00:00
Gleb Popov
30dfc99c94 inotify: Optimize consecutive g_hash_table_{lookup,remove} calls 2024-09-19 10:55:39 +03:00
Gleb Popov
697118dfd5 Adapt testfilemonitor.c for libinotify-kqueue backend
The backend mimics inotify but is still subject to kevent idionsyncracies.
2024-09-19 09:55:01 +03:00
Gleb Popov
7460faf861 giomodule: Adapt to the GFileMintor backend selection changes
Instead of relying on some headers/functions presence, the buildsystem now
tells us what backend we're using.
2024-09-19 09:55:01 +03:00
Gleb Popov
dae3b8bd15 Introduce a special mode of operating for the inotify GFileMonitor backend
libinotify-kqueue is a library that implements inotify interface in terms of
kqueue/kevent API available on Mac OS and *BSD systems. The original kqueue
backend seems to be a predecessor version of the code that is currently present
in libinotify-kqueue. Under the hood the library implements a sophisticated
filesystem changes detection algorithm that is derived from the glib backend
code.

Updating the native glib kqueue backend requires substantial work, because code
bases have diverged greatly. Another approach is taken, instead. libinotify-kqueue
can serve as a drop-in replacement for Linux inotify API, thus allowing to
reuse the inotify backend code. The compatibility, however, comes at cost, since
the library has to emulate the inotify descriptor via an unix domain socket.
This means that delivering an event involves copying the data into the kernel
and then pulling it back.

The recent libinotify-kqueue release adds a new mode of operation called "direct".
In this mode the socket pipe is replaced with another kqueue that is used to
deliver events via a kevent(EVFILT_USER) call.
Employing the direct mode requires minor changes to the client code compared
to using plain inotify API, but in return it allows for reusing libinotify's
algorithms without a performance penalty. Luckily, all required changes are
consolidated in one file called inotify-kernel.c

This puts us in the best of possible worlds. On one hand we share a lot of code
with glib inotify backend, which is far more thoroughly tested and widely used.
On the other we support a range of non-Linux systems and consolidate the business
logic in one library. I plan to do the same trick for QFileSystemWatcher which
will give us the same behaviour between Gtk and Qt applications.

The glib test suite passes for both old kqueue backend and new libinotify-kqueue
one. However, the AppStream FileMonitor tests are failing with the old backend,
but pass with the new one, so this is still an observable improvement.

Relevant libinotify-kqueue PR: https://github.com/libinotify-kqueue/libinotify-kqueue/pull/19
2024-09-19 09:54:56 +03:00
Philip Withnall
5948a76f43 Merge branch 'wip/smcv/gdbus-silence-cross-ns' into 'main'
GDBus: Don't log a message for G_DBUS_CONNECTION_FLAGS_CROSS_NAMESPACE

See merge request GNOME/glib!4278
2024-09-18 20:57:55 +00:00