Commit Graph

8191 Commits

Author SHA1 Message Date
Marco Trevisan
a3488a38e7 Merge branch 'wip/add-built-headers-deps-v2' into 'main'
meson: Cleanup and fix include files paths, using base path without repetitions

See merge request GNOME/glib!3011
2022-10-25 09:14:15 +00:00
Simon McVittie
7b05defa0e Merge branch 'wip/smcv/pointers-can-be-large' into 'main'
docs: Stop claiming that gsize is wide enough to hold a pointer

See merge request GNOME/glib!3000
2022-10-24 20:29:07 +00:00
Philip Withnall
e33f23a6b5 Merge branch 'wip/smcv/64-bit-hash' into 'main'
ghash: Correctly retrieve low 32 bits of 64-bit values

Closes #2787

See merge request GNOME/glib!2994
2022-10-24 20:22:15 +00:00
Philip Withnall
521d481d64 Merge branch 'wip/smcv/standard-offsetof' into 'main'
docs: Soft-deprecate G_STRUCT_OFFSET in favour of offsetof

See merge request GNOME/glib!3002
2022-10-24 20:09:54 +00:00
Marco Trevisan (Treviño)
0de22a8864 tests/strfuncs: Do not compare string literal with pointers
Otherwise clang would complain:

  ../glib/tests/strfuncs.c:2603:32: warning: result of comparison
    against a string literal is unspecified (use an explicit string
    comparison function instead) [-Wstring-compare]
    g_assert_true ((gpointer)str != (gpointer)"");
                                 ^  ~~~~~~~~~~~~
  ../glib/gtestutils.h:187:59: note: expanded from macro 'g_assert_true'
                                               if G_LIKELY (expr) ; else \
                                                            ^~~~
  ../glib/gmacros.h:1186:59: note: expanded from macro 'G_LIKELY'
  #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
                                                            ^~~~
  ../glib/gmacros.h:1180:8: note: expanded from macro '_G_BOOLEAN_EXPR'
     if (expr)
2022-10-24 21:34:35 +02:00
Marco Trevisan (Treviño)
8341a1cf06 tests/sequence: Ensure iterator is set and actually checked
Clang was complaining:

  ../glib/tests/sequence.c:125:7: warning: variable 'i' set but not used
    int i;
        ^
  1 warning generated.
2022-10-24 21:33:18 +02:00
Marco Trevisan (Treviño)
836fd0563d meson: Remove unneeded install_tag's on headers
Meson is able to handle this automatically when we're installing in the
include-dir prefix.
2022-10-24 21:09:49 +02:00
Marco Trevisan (Treviño)
6dd222e753 meson: Cleanup include-dir paths, use base path without repetitions
Avoid setting the subdir all the times, just use the global definition
plus the specific module subdir
2022-10-24 21:09:09 +02:00
Philip Withnall
5553a44b1b gfileutils: Mention possibility of relative paths in g_file_read_link()
It’s entirely possible that `g_file_read_link()` will return a relative
path. Mention that in the documentation, and include a short example of
how to make the path absolute for further computation.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-24 12:38:15 +01:00
Philip Withnall
f8c80391ae gtimezone: Fix symlink checks on relative link targets
The changes in 6265b2e6f7 to reject weird
`/etc/localtime` configurations where `/etc/localtime` links to another
symlink did not consider the case where the target of `/etc/localtime`
is a *relative* path. They only considered the case where the target is
absolute.

Relative paths are permissible in all symlinks. On my Fedora 36 system,
`/etc/localtime`’s target is `../usr/share/zoneinfo/Europe/London`.

Fix the check for toolbx by resolving relative paths before calling
`g_lstat()` on them.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-24 12:35:29 +01:00
Simon McVittie
64945e6386 docs: Stop claiming that gsize is wide enough to hold a pointer
Standard C specifically does not guarantee this, and it's untrue on
CHERI architectures (which have 128-bit pointers into a 64-bit
address space, with the remaining bits used for a capability-like
mechanism).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 11:11:18 +01:00
Simon McVittie
de7abf54c7 ghash: Correctly retrieve low 32 bits of 64-bit values
Dereferencing a pointer to a 64-bit object as though it was a 32-bit
object is the same as taking the least significant 32 bits on a
little-endian machine, but on a big-endian machine it is the same as
taking the *most* significant 32 bits, which would result in these hash
functions always hashing to zero. The /hash/int64/collisions and
/hash/double/collisions test-cases in glib/tests/hash.c detect this
and fail.

Instead, fetch the whole 64-bit quantity and do the bit-manipulation
to xor the more significant half with the less significant half in an
architecture-neutral way.

Fixes: dd1f4f70 "Optimize g_double_hash implementation"
Fixes: c1af4b2b "Optional optimization for `g_int64_hash`"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2787
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 10:46:57 +01:00
Simon McVittie
8e752b2733 docs: Soft-deprecate G_STRUCT_OFFSET in favour of offsetof
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 10:43:43 +01:00
Marco Trevisan (Treviño)
681bb3cb21 gnulib: Add glib built headers to the gnulib_lib required sources
g-gnulib.h includes glib.h that requires some headers to be generated,
so ensure that this is always the case.

See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2349167
2022-10-23 18:04:56 +02:00
Marco Trevisan (Treviño)
f67743e9a2 glib: Also include glibconfig.h in the libglib dependencies and sources
It must be there to build, or we'd fail:

See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2346909
2022-10-23 18:04:56 +02:00
Marco Trevisan (Treviño)
341895a19e glib, gmodule, gobject: Add generated headers to the lib dependency
This requires changing them from being generated sources at compile time
to custom targets, but it also ensures that they are actually there when
needed, in fact currently we may instead try to compile files that requires
them without having been generated yet.

See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2346914 (glib)
See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2344802 (gmodule)
See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2345205 (gobject)
2022-10-23 18:04:56 +02:00
Marco Trevisan (Treviño)
7e5c5932fc meson: cleanup libglib dependencies
Move it multi-line to keep it more readable
2022-10-23 18:04:55 +02:00
Philip Withnall
1db9066485 Merge branch 'fix-gstrerror-warning' into 'main'
gstrfuncs: Fix a compiler warning in g_strerror()

See merge request GNOME/glib!2956
2022-10-20 12:36:27 +00:00
Philip Withnall
4dcb7f1f9f Merge branch '2753-vasprintf-loop' into 'main'
gprintf: Avoid an infinite loop on ENOMEM in g_vasprintf()

Closes #2753

See merge request GNOME/glib!2944
2022-10-20 12:29:11 +00:00
Marco Trevisan
e49c4b1a9e Merge branch 'python-code-style-again' into 'main'
tests: Fix code style in Python files to satisfy black and flake8

See merge request GNOME/glib!2984
2022-10-20 11:59:53 +00:00
Michael Catanzaro
21a784920d Merge branch 'th/gspawn-no-safe-close' into 'main'
gspawn: avoid race due to retry with EINTR on close()

See merge request GNOME/glib!2947
2022-10-20 11:55:08 +00:00
Thomas Haller
d6790aecca gspawn: use g_close()
g_close() now is async-signal-safe, as long as we don't request a GError
and pass a valid file descriptor.

Update "gspawn.c" to drop its safe_close() function and use
g_close() instead.
2022-10-20 08:16:52 +02:00
Thomas Haller
3ed7f4d1ed gstdio: make g_close() async-signal-safe under certain conditions
g_close() does something useful. It is not trivial to get EINTR handling of
close() right, in a portable manner. g_close() abstracts this.

We should allow glib users to use the function even in async-signal-safe
contexts, at least if the user heeds the caveat about GError and take care
not to fail assertions.
2022-10-20 08:16:38 +02:00
Marco Trevisan (Treviño)
476e33c3f3 gio, glib: Use G_OS_DARWIN for code that is for such environments
While we preserved the COCOA/CARBON cases when specific libraries are
needed.
2022-10-20 03:37:21 +02:00
Marco Trevisan (Treviño)
e85635daa0 meson: Define G_OS_DARWIN when compiling under OSX or iOS
It has enough differences to expose it as an unix-subtype.
2022-10-20 03:37:03 +02:00
Thomas Haller
6418db829b gspawn: avoid race due to retry with EINTR on close()
Retry on EINTR is wrong on many OS, including Linux. See the comment
in g_close() why that is.

As we cannot use g_close() after fork, we had safe_close(). This had the
wrong retry loop on EINTR. Drop that.

This was especially problematic since commit 6f46294227 ('gspawn: Don’t
use g_close() in async-signal-safe context'). Before, safe_close() was
only called after fork, where there is only one thread and there is no
concern about a race.

This patch only exists for easier backporting of the bugfix. The code
will be reworked further next.

Fixes: 6f46294227 ('gspawn: Don’t use g_close() in async-signal-safe context')
2022-10-19 20:54:18 +02:00
Matthias Clasen
65536b079d gstrfuncs: Fix a compiler warning in g_strerror()
MSVC is complaining about this code. Let’s try
to help it see the light.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2800
2022-10-19 14:53:45 +01:00
Philip Withnall
59541e335a tests: Fix code style in Python files to satisfy black and flake8
This should make the style-check-diff CI job happy again.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-19 12:28:08 +01:00
Philip Withnall
7cc95e0211 Merge branch 'wip/pwithnall/2785-macos-fd-close-test-failure' into 'main'
gstdio: Temporarily disable g_close() warning on macOS

See merge request GNOME/glib!2977
2022-10-19 09:52:29 +00:00
Philip Withnall
0839556904 Merge branch 'gmessages-handle-unused-write-results' into 'main'
gmessages: Handle unused results from fputs and fwrite

Closes #2758

See merge request GNOME/glib!2910
2022-10-19 09:23:52 +00:00
Marco Trevisan (Treviño)
977b734e0b gmessages: Handle unused results from fputs and fwrite
Fixes: #2758
2022-10-18 19:41:18 +02:00
Marco Trevisan
ba961b90d9 Merge branch 'log-fallback-handler-newline' into 'main'
gmessages: Add missing trailing newline in fallback log handler

See merge request GNOME/glib!2945
2022-10-18 16:38:59 +00:00
Marco Trevisan
066ca6b042 Merge branch 'coverity-issues' into 'main'
Fix a couple of minor Coverity issues

See merge request GNOME/glib!2976
2022-10-18 15:03:06 +00:00
Philip Withnall
9965d0cdc7 Merge branch '2782-gvariant-recursion-typedecl-fix' into 'main'
gvariant-parser: Reject deeply-nested typedecls in text form variants

Closes #2782

See merge request GNOME/glib!2974
2022-10-18 14:50:25 +00:00
Philip Withnall
5190354ad9 gstdio: Temporarily disable g_close() warning on macOS
It causes the tests to fail, which suggests some latent FD handling bug
on macOS (but not other platforms).

Unfortunately I’m unable to debug that due to not having access to a
macOS machine, and it’s blocking CI for the rest of the project.

So disable it on macOS for now, until someone with access to a macOS
machine can take a look.

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

Helps: #2785
2022-10-18 15:41:30 +01:00
Marco Trevisan
f8674c1d4c Merge branch 'g_str_has_optimization' into 'main'
Optimize g_str_has_*() functions to  detect static arguments

Closes #24

See merge request GNOME/glib!2859
2022-10-18 14:15:56 +00:00
Philip Withnall
4fca3bba8f gregex: Remove an unreachable return statement
Spotted by Coverity.

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

Coverity CID: #1497916
2022-10-18 15:05:30 +01:00
Philip Withnall
3e313438f1 gvariant-parser: Reject deeply-nested typedecls in text form variants
Return `G_VARIANT_PARSE_ERROR_RECURSION` from `g_variant_parse()` if a
typedecl is found within a text-form variant which would cause any part
of the variant to exceed the maximum allowed recursion/nesting depth.

This fixes an oversight when `G_VARIANT_MAX_RECURSION_DEPTH` was
implemented, which allowed typedecls to effectively multiply the size of
an array if `g_variant_parse()` was parsing a text-form variant without
a top-level concrete type specified.

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

Fixes: #2782
oss-fuzz#49462
2022-10-18 14:52:32 +01:00
Ray Strode
2e627803e7 Merge branch 'fix-GTimeZone-in-toolbx' into 'main'
gtimezone: Reject weird /etc/localtime configurations

See merge request GNOME/glib!2955
2022-10-18 13:39:44 +00:00
Philip Withnall
8d02465ea8 Merge branch 'th/hash-steal-doc' into 'main'
ghash: comment g_hash_table_steal_extended() about not destroying key/value

See merge request GNOME/glib!2965
2022-10-18 13:37:14 +00:00
Ray Strode
6265b2e6f7 gtimezone: Reject weird /etc/localtime configurations
At the moment, glib assumes that if /etc/localtime is a symlink,
that it's a symlink to zoneinfo file.

Toolbx containers add an extra layer of indirection though, making
it a symlink to a symlink to a zoneinfo file.

This commit deals with the problem, by performing additional checks
on /etc/localtime and ignoring it if those check fail, falling back
instead to reading /etc/timezone.
2022-10-18 08:59:24 -04:00
Thomas Haller
4a709d0b46 ghash: comment g_hash_table_steal_extended() about not destroying key/value
The previous text was technically correct, but not very clear what
happens with the ownership of the key/value if it was not returned.
Elaborate on the fact, that the key/value is never destroyed, even if
not requested by the user.

I intuitively expected the function to behave differently, that is, to
destroy the key/value if (and only if) it was not returned. That is,
when the function does not return a pointer, then it would destroy it.
That would seem more consistent to me, where ownership is either
transferred to the caller, or the resource destroyed during the steal.

On the other hand, the existing behaviors is:

- is consistent with g_hash_table_steal() and never destroys key/value.
- behaves the same, regardless whether the key/value was returned.

So the existing behavior may be better.

Just elaborate on that detail in the doc.
2022-10-18 13:57:43 +01:00
Thomas Haller
d5dc7d266f gstdio: fail assertion in g_close() for invalid file descriptor (EBADF)
An application must keep track of the file descriptors that it
has. Closing an invalid, non-negative file descriptor is usually
a bug, because it indicates somebody messed up the tracking.

On a single threaded application it may be fine, but EBADF is always a bug
in a multi threaded application because another thread might race
reusing the bad file descriptor. With GDBus and other glib API, it is very
common that your application has multiple threads running and this is
in fact a bug.

The assertion failure does not necessarily indicate that the bug
is in the caller. It could have been another part of the application
that wrongly closed the file descriptor.
2022-10-18 13:57:14 +01:00
Philip Withnall
2715e91ee9 Merge branch 'fix-visibility' into 'main'
Fix include order of glib-visibility.h

See merge request GNOME/glib!2957
2022-10-17 16:15:40 +00:00
Philip Withnall
a55c0dc403 Merge branch '2754-sort-locale' into 'main'
tests: Don’t rely on output locale of sort in spawn-test

Closes #2754

See merge request GNOME/glib!2943
2022-10-17 16:12:46 +00:00
Xavier Claessens
0db49cc57b Fix include order of glib-visibility.h
It uses macros from glibconfig.h, gmacros.h and gversionmacros.h, makes
sure it is included after them.
2022-10-17 15:17:32 +02:00
Philip Withnall
360fc4cda3 tests: Don’t rely on output locale of sort in spawn-test
Otherwise the test will fail when run in a non-English locale.

Fix suggested by Simon McVittie.

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

Fixes: #2754
2022-10-17 13:51:34 +01:00
Emmanuel Fleury
c7f24df744 Check for prefix/suffix smaller than string and check for non-inlined function
* Add a test to check that smaller string than prefix/suffix are
  handled in g_str_has_*() functions.

* Add a tests on macro prefixed function and ensure that function
  itselves are tested as well.
2022-10-17 14:40:32 +02:00
Emmanuel Fleury
bbd3ad8c00 Optimize g_str_has_*() functions to detect const arguments at compile-time
Compilers can emit optimized code for str|strn|mem)cmp(str,"literal")
at compile-time. This commit use the preprocessor to introduce this
kind of optimization for the functions g_str_has_prefix() and
g_str_has_suffix().

Original work by Ben @bdejean

Closes issue #24
2022-10-17 14:40:31 +02:00
Philip Withnall
06ff700ad8 tests: Fix checks for line endings in spawn-test on Windows
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-17 13:06:36 +01:00
Philip Withnall
292c117b98 Merge branch 'w32-tests' into 'main'
Various win32 test fixes

See merge request GNOME/glib!2952
2022-10-17 09:53:44 +00:00
Marc-André Lureau
99847d36ed tests/thread-pool-slow: do not pass confusing value to sort function
That value isn't used by the callback.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:56:24 +04:00
Marc-André Lureau
2df5acf60a tests/thread-pool-slow: change num-threads limit check
There is no guarantee that the thread pool will reach its limit afaict,
it depends how the system schedule the various threads. This fixes
random test failure on win32.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:55:05 +04:00
Marc-André Lureau
52a49eb9c2 tests/assert-msg-test: fix opening temporary file in GDB
On Win32, the file cannot be opened a second time, it must be closed
first.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:49:19 +04:00
Marc-André Lureau
6dcd7fe5e8 tests/assert-msg-test: abort() exit code is 3 on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:45:06 +04:00
Marc-André Lureau
0a4dc17f28 tests/assert-msg-test: it is not a script (anymore?)
Fixes running the program on win32.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:45:01 +04:00
Marc-André Lureau
789fd5dfc0 tests/assert-msg-test: add exe extension on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 10:45:00 +04:00
Philip Withnall
5215463a03 Merge branch 'wip/chergert/g_set_str' into 'main'
strfuncs: add g_set_str()

Closes #2747

See merge request GNOME/glib!2927
2022-10-15 22:30:18 +00:00
Philip Withnall
4bc284fca6 Merge branch 'wip/smcv/deprecated-prop-followup' into 'main'
Run tests with G_ENABLE_DIAGNOSTIC=1

See merge request GNOME/glib!2889
2022-10-15 21:31:29 +00:00
Marco Trevisan (Treviño)
2e8375daa0 gbookmarkfile: Add copy function
GBookmarkFile has everything for being introspectable, but it lacks a
GType, because it can't be copied. So provide a copy function that
deeply copies all the bookmark structures.

Add tests for this.
2022-10-14 16:39:20 +01:00
Marco Trevisan (Treviño)
5f604460ef gbookmarkfile: Do not try to write invalid modified stamp
In some bookmarks that we load the modified value may be not set, while
this may lead to a load error, we still can dump such file and this
would fail as we try to get a string from an invalid time.

Avoid this, because it would also lead to not writing a valid count
value, given that we'd pass NULL to g_strconcat too early.
2022-10-14 16:39:20 +01:00
Christian Hergert
49ae9b490d strfuncs: add g_set_str()
This is like our other suite of g_set_*() based APIs to simplify and
improve correctness of setters for fields, properties, and more.

This implementation specifically handles setting string values that may
point to an offset within the current string by copying before free.

strcmp() is used directly (as opposed to g_strcmp0() due to it being in
gtestutils.h as well as to increase the chance that the compiler will
hoist the implementation.

Fixes #2747
2022-10-14 16:24:41 +01:00
Xavier Claessens
a5eeb465ed Merge branch 'visibility' into 'main'
Fix symbol visibility macros on Windows

See merge request GNOME/glib!2936
2022-10-14 11:47:41 +00:00
Thomas Haller
99bedd110c ghash: document g_hash_table_steal_extended() behavior for sets 2022-10-14 08:03:43 +00:00
Xavier Claessens
dcfc9f689e Fix symbol visibility macros on Windows
There is currently no `dllimport` attribute on any of our function,
which prevents MSVC to optimize function calls.

To fix that issue, we need to redeclare all our visibility macros for
each of our libraries, because when compiling e.g. GIO code, we need
dllimport in GLIB headers and dllexport in GIO headers. That means they
cannot use the same GLIB_AVAILABLE_* macro.

Since that's a lot of boilerplate to copy/paste after each version bump,
this MR generate all those macros using a python script.

Also simplify the meson side by using `gnu_symbol_visibility : 'hidden'`
keyword argument instead of passing the cflag manually.

This leaves only API index to add manually into glib-docs.xml when
bumping GLib version. That file cannot be generated because Meson does
not allow passing a buit file to gnome.gtkdoc()'s main_xml kwarg
unfortunately.
2022-10-13 20:53:56 -04:00
Xavier Claessens
d40459c280 Simplify G_HAVE_GNUC_VISIBILITY definition
There is no need of compiler checks, GNUC visibility should be used when
__GNUC__ >= 4 but not on Windows.
2022-10-13 20:52:49 -04:00
Emmanuele Bassi
80f56c9eb4 doc: Correctly annotate GAsyncQueue methods
Generic pointers are assumed to be nullable unless explicitly marked as
not nullable.
2022-10-13 23:56:18 +01:00
Marco Trevisan
9fb7edd845 Merge branch 'fileutils-fwrite-retval' into 'main'
tests: Check the return value of fwrite() in a test

See merge request GNOME/glib!2946
2022-10-13 21:04:39 +00:00
Philip Withnall
d6c29b538a tests: Check the return value of fwrite() in a test
Not that we ever expect it to fail. This is basically just to silence a
compiler warning with `-Werror=unused-result`.

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

Helps: #2758
2022-10-13 15:48:47 +01:00
John Lindgren
d01fb41280 gmessages: Add missing trailing newline in fallback log handler
This makes the fallback log handler match the behaviour of the default
log handlers.

Spotted as part of https://gitlab.gnome.org/GNOME/glib/-/issues/2753
2022-10-13 14:00:12 +01:00
Philip Withnall
b204b46fc0 gprintf: Avoid an infinite loop on ENOMEM in g_vasprintf()
Instead of going through the normal error logging code, which does
further allocations and will potentially call back into `g_vasprintf()`
and create an infinite loop, just `fputs()` an error message and abort.
If we’re getting `ENOMEM` the process is doomed anyway.

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

Fixes: #2753
2022-10-13 13:54:24 +01:00
Alyssa Ross
1dc8d69edb tests: skip shared libs if default_library=static
Otherwise, the build will fail when the toolchain is static-only, even
with -Ddefault_library=static.  I talked to a Meson developer in their
IRC channel, who told me that the correct fix was to ensure that
shared_library is only used if default_library != static.
2022-10-12 16:49:39 +01:00
Philip Withnall
0cdbc530ca Merge branch 'regex-errors-msg-cleanups' into 'main'
gregex: Use pcre2 error messages if we don't provide a specific one

See merge request GNOME/glib!2913
2022-10-12 13:48:29 +00:00
Philip Withnall
e90733a457 Merge branch 'atomic-older-cplusplus' into 'main'
gatomic: fix the atomic compare_and_exchange macros on older C++ standard versions

See merge request GNOME/glib!2864
2022-10-12 09:56:19 +00:00
Philip Withnall
61ef7a7ec2 Merge branch 'strugee-main-patch-02389' into 'main'
Fix style warning in gvariant.c

See merge request GNOME/glib!2933
2022-10-11 19:50:10 +00:00
Matthias Clasen
db1aadaa5e Merge branch 'str-equal-only' into 'main'
g_str_equal: Provide macro for optimization

Closes #2775

See merge request GNOME/glib!2940
2022-10-11 18:19:25 +00:00
Xavier Claessens
6e341750df g_str_equal: Provide macro for optimization
g_str_equal() is a nicer API than strcmp()==0, and less error prone.
However, forcing a function call prevents compiler from doing
optimizations. In the case it is not used as callback to GHashTable,
provide a macro that calls strcmp directly. This also has the side
effect that it forces arguments to be `const char *` instead of
`gconstpointer` in the case it is not used as callback, which adds type
safety.

Fixes: #2775
2022-10-11 10:55:56 -04:00
Marco Trevisan
4231426abe Merge branch 'optimize_g_double_hash' into 'main'
Optimize the implementation of `g_double_hash`

See merge request GNOME/glib!2924
2022-10-11 11:26:41 +00:00
星外之神
e02db8ea22 Add tests for hash collisions in simple cases 2022-10-11 13:12:20 +02:00
wszqkzqk
c1af4b2b88 Optional optimization for g_int64_hash 2022-10-11 13:12:20 +02:00
wszqkzqk
dd1f4f709e Optimize g_double_hash implementation 2022-10-11 13:12:20 +02:00
Marco Trevisan
cc02e8720d Merge branch 'unicode-15' into 'main'
Unicode 15 support

Closes #2735

See merge request GNOME/glib!2877
2022-10-10 14:20:17 +00:00
Marco Trevisan
8f2711bf72 Merge branch 'log-field-nul-termination-2' into 'main'
Update version in the docs to 2.74.1 for the fixed handling of...

See merge request GNOME/glib!2916
2022-10-10 12:33:57 +00:00
Peter Bloomfield
574a2ecfa9 gdatetime: add NULL guard in g_date_time_new_now()
Add a missing g_return_() check in g_date_time_new_now().
A clear warning is better than a NULL pointer dereference.
2022-10-09 19:39:58 -04:00
AJ Jordan
e052dddd1d Fix style warning in gvariant.c 2022-10-05 06:47:26 +00:00
Aleksander Morgado
737ca7de91 gdatetime: add missing g_return_() check in g_date_time_format_iso8601
A clear warning is better than a NULL pointer dereference.

Signed-off-by: Aleksander Morgado <aleksandermj@chromium.org>
2022-10-04 21:37:58 +00:00
Guido Günther
664ee9ca6a gregex: Drop explanation G_REGEX_JAVASCRIPT_COMPAT
It's not supported as of glib 2.74
2022-09-27 13:52:05 +02:00
Guido Günther
a164b49532 gregex: Allow G_REGEX_JAVASCRIPT_COMPAT in compile mask for g_regex_new
The flag is still ignored but this way we properly deprecate
at compile time without raising an unexpected criticals at runtime:

   g_regex_new: assertion '(compile_options & ~G_REGEX_COMPILE_MASK) == 0' failed

and then failing to create the regex completely.

Fixes 8d5a44dc8 ("replace pcre1 with pcre2")
2022-09-27 13:52:05 +02:00
Sebastian Dröge
54abb0f17b Update version in the docs to 2.74.1 for the fixed handling of non-NUL-terminated structured logging strings 2022-09-22 15:57:01 +03:00
Sebastian Dröge
cfdcdaacc1 Consider the GLogField.length of "MESSAGE"/"GLIB_DOMAIN" fields in g_log_writer_format_fields()
Previously it was wrongly assuming that a NUL-termianted string is
passed and the whole string should be written out.

Also document this bug in the documentation of g_log_structured() to
avoid surprises when using older GLib versions.
2022-09-22 15:09:56 +03:00
Marco Trevisan (Treviño)
0f869ec5c6 regex: Use critical messages if an unexpected NULL parameter is provided
As programmer error we should be consistent in using criticals.
2022-09-21 13:48:18 +02:00
Marco Trevisan (Treviño)
6caf952e48 gregex: Use pcre2 error messages if we don't provide a specific one
In case we got a compilation or match error we should try to provide
some useful error message, if possible, before returning a quite obscure
"internal error" or "unknown error" string.

So rely on PCRE2 strings even if they're not translated they can provide
better information than the ones we're currently giving.

Related to: https://gitlab.gnome.org/GNOME/glib/-/issues/2691
Related to: https://gitlab.gnome.org/GNOME/glib/-/issues/2760
2022-09-21 13:47:56 +02:00
Simon McVittie
88e160dfe4 tests: Move common test environment variables to top level
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-21 11:19:28 +01:00
Marco Trevisan
87b4771d1f Merge branch 'install-tag-2' into 'main'
meson: Set install_tag remaining installed files

See merge request GNOME/glib!2905
2022-09-21 10:05:18 +00:00
Xavier Claessens
a73ca336aa meson: Set install_tag on remaining installed files 2022-09-20 11:30:12 -04:00
Xavier Claessens
49fd523af3 meson: Set install_tag on systemtap files
This could be done automatically by Meson, this commit can be reverted
when we have that Meson PR in our CI:
https://github.com/mesonbuild/meson/pull/10829
2022-09-20 11:30:02 -04:00
Xavier Claessens
c00df192ee meson: Set install_tag on installed tests files
This could be done automatically by Meson, this commit can be reverted
when we have that Meson PR in our CI:
https://github.com/mesonbuild/meson/pull/10829
2022-09-20 11:30:02 -04:00
Biswapriyo Nath
4f72d3bce7 gthread-win32: Fix conversion error from pointer to integer
glib/gthread-win32.c:359:16: error: incompatible integer to pointer conversion passing 'DWORD' (aka 'unsigned long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]
          if (!g_atomic_pointer_compare_and_exchange (&key->p, NULL, impl))
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glib/gatomic.h:257:73: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
    __atomic_compare_exchange_n ((atomic), (void *) (&(gapcae_oldval)), (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                                                        ^~~~~~~~
2022-09-20 20:28:53 +05:30
Marco Trevisan
871d4f9ccc Merge branch 'tests-error-musl' into 'main'
tests: Only run g_error_new_valist() programmer error test on glibc

See merge request GNOME/glib!2904
2022-09-19 14:38:25 +00:00
Marco Trevisan
7e9625a79b Merge branch 'handling_collision_over_standard_file_descriptors' into 'main'
Handling collision between standard i/o file descriptors and newly created ones

Closes #16

See merge request GNOME/glib!2846
2022-09-19 14:35:45 +00:00
Marco Trevisan
13776b4942 Merge branch 'wip/sadiq/fix-bt-lines-cut' into 'main'
gbacktrace: Don't truncate gdb output

See merge request GNOME/glib!2880
2022-09-19 14:33:14 +00:00
Michal Vasilek
902ba0bc0d tests: Only run g_error_new_valist() programmer error test on glibc
The musl implementation of vasprintf segfaults with NULL
2022-09-18 18:01:40 +02:00
Tom Levy
bd3abd0bde docs: Fix markup error in code blocks for "DEPRECATED" macros 2022-09-18 13:09:09 +00:00
Tom Levy
eeaef8b950 docs: Improve wording in documentation of g_unix_signal_source_new()
- Insert missing word "from".

- Remove space between function name and "()" so syntax highlighting
  can recognise it as a function.

- Avoid "you"/"your" when discussing the reentrancy issues of regular
  UNIX signal handlers, because it gives the false impression that
  these issues are applicable to g_unix_signal_source_new().

Unrelated:

- Fix missing space in documentation of g_signal_new_class_handler().
2022-09-16 08:25:46 +00:00
Matthias Clasen
dcb459a0b0 Fix g_unichar_iswide for unassigned codepoints
There are a few blocks in Unicode (mainly ideographs)
which default to wide. These blocks are defined in the
header comment of EastAsianWidth.txt.

We have some tests which check that unassigned codepoints
in those blocks get reported as wide, so make sure we handle
this correctly.
2022-09-15 03:43:04 +02:00
Marco Trevisan (Treviño)
b3e32eda7c tests/unicode: Add more debugging messages 2022-09-15 03:43:04 +02:00
Marco Trevisan (Treviño)
0eb3a2440a unicode: Avoid adding trailing spaces to tables definitions 2022-09-15 03:43:04 +02:00
Marco Trevisan (Treviño)
65092de98f unicode: Update data to Unicode 15 2022-09-15 03:43:04 +02:00
Marco Trevisan (Treviño)
9b6cc47bcb glib/glib-typeof: Ensure glib_typeof is defined in MSCV C++
When compiling with C++ in MSCV, it defines the __cplusplus macro, but
that's set to an old value and it doesn't represent the current c++
standard version (unless when explicitly requested via `/Zc:__cplusplus`).

So, to enable modern features we should rely on `_MSC_LANG` instead,
which represent the value we care about.
2022-09-15 01:18:42 +02:00
Marco Trevisan (Treviño)
c19904d6e8 glib/tests/cxx: Enable the c++ tests for all the C++ versions
We should support these macros everywhere, if not, we should fix them
again.
2022-09-15 01:18:42 +02:00
Damjan Jovanovic
a0f200593c gatomic: Support atomic compare_and_exchange macros on older C++ standard versions
The fix in ad23894c15 only works for
__cplusplus >= 201103L, but older C++ standards are not always less strict,
and still fail to compile the g_atomic_int_compare_and_exchange() and
g_atomic_pointer_compare_and_exchange() macros.

Apply that fix to all C++ standard versions.

Even if this implies using functions that have been added as part of
C++11 specification, this is safe because we wouldn't ever try to use the
`__atomic_...()` APIs if `__ATOMIC_SEQ_CST` is not defined, and that's part
of the very same API.
2022-09-15 01:18:42 +02:00
Marco Trevisan (Treviño)
0abb82498e glib/tests/cxx: Add clear and steal pointer functions tests
These functions may be defined as macros with different behaviors in
different c++ versions (as they rely on glib_typeof), so let's ensure
they work and compile everywhere.
2022-09-15 01:18:42 +02:00
Damjan Jovanovic
d050ad8a3c glib-typeof: Define glib_typeof on on older C++ standard versions
When using an older C++ versions, the glib_typeof() macro is never
defined, as the C++ definition depends on __cplusplus >= 201103L, while the C
definition, which would work, depends on !defined(__cplusplus).
Allow old C++ versions to use the C macro definition for glib_typeof().
2022-09-15 01:18:42 +02:00
Marco Trevisan (Treviño)
1cbe7a6734 meson: Build C++ tests for the currently supported C++ standard versions
We've various macros definitions that are depending using C++ features
that may not work in all the standard versions, so recompile the cxx
tests that we have in all the ones we want to support.
2022-09-15 01:18:40 +02:00
Emmanuel Fleury
d9ba615090 Handling collision between standard i/o file descriptors and newly created ones
Though unlikely to happen, it may happen that newly created file
descriptor take the value 0 (stdin), 1 (stdout) or 2 (stderr) if one
of the standard ones have been dismissed in between. So, it may
confuse the program if it is unaware of this change.

The point of this patch is to avoid a reasign of standard file
descriptors on newly created ones.

Closes issue #16
2022-09-14 08:50:40 +02:00
Marco Trevisan
0d823aa926 Merge branch 'wip/3v1n0/regex-pcre2-flags-fixes' into 'main'
GRegex flags fixes and cleanups

Closes gtksourceview#283, #2741, #2729, #2688 e gtksourceview#278

See merge request GNOME/glib!2878
2022-09-12 21:45:57 +00:00
Xavier Claessens
a1c78d63ef meson: Set install_tag on all tools
Those tools are not needed at runtime for typical applications,
distributions typically package them separately.

This makes `meson install --tag runtime` skip installation of those
tools. Omitting `--tag` argument will still install them, as well as
with `--tag bin,bin-devel`.

See https://mesonbuild.com/Installing.html#installation-tags.
2022-09-12 09:50:31 -04:00
Marco Trevisan (Treviño)
653f8eb020 tests/regex: Perform more tests both with and without optimizations 2022-09-12 14:08:13 +02:00
Marco Trevisan (Treviño)
bec68b2d74 glib/regex: Do not use JIT when using unsupported match options
Do not store jit status for regex unless during initial compilation.
After that, decide whether to use it depending on matching options.

In fact there are some matching options that are incompatible with JIT,
as the PCRE2 docs states:

  Setting PCRE2_ANCHORED or PCRE2_ENDANCHORED at match time is not
  supported by the just-in-time (JIT) compiler. If it is set, JIT
  matching is disabled and the interpretive code in pcre2_match() is
  run. Apart from PCRE2_NO_JIT (obviously), the remaining options are
  supported for JIT matching.

Fixes: GNOME/gtksourceview#283
2022-09-12 14:08:13 +02:00
Marco Trevisan (Treviño)
0831393dd0 tests/regex: Make possible to test replacements with options 2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
5e76cde5ff regex: Handle JIT errors more explicitly 2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
fe1c2628d5 regex: Avoid allocating offsets until we've a match
There's no much point of pre-allocating offsets given that we're doing
this when needed if only have matches to store.

So let's just allocate the spaces for the dummy offset we depend on,
while allocate the others on demand.
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
e8628a7ed5 regex: Compute the offsets size based on match results
While the ovector count would include all the allocated space, we only
care about the actual match values, so avoid wasting allocations and
just use the ones we need to hold the offsets.
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
aee84cb45c gregex: Avoid re-allocating if we have no size change
This is handled by the syscall underneath, but we can just avoid a call
cheaply.
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
11521972f4 gregex: Handle the case we need to re-allocate the match data
In case PCRE2 returns an empty match

This can be easily tested by initializing the initial match data to a
value that is less than the expected match values (e.g. by calling
pcre2_match_data_create (1, NULL)), but we can't do it in our tests
without bigger changes.
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
1d628dac92 regex: Use size types more in line with PCRE2 returned values
We're using int for every size value while PCRE uses uint_32t or
PCRE2_SIZE (size_t in most platforms), let's use the same types to avoid
using different signs.
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
13ad4296ea gregex: Fix a potential PCRE2 code leak on reallocation failures
In case recalc_match_offsets() failed we were just returning, but in
such case, per the documentation we should still set the match_info (if
provided) and free the pcre2 code instance.

So let's just break the loop we're in it, as if we we've no matches set.
This also avoids re-allocating the offsets array and potentially
accessing to unset data.
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
1f88976610 gregex: Do not try access the undefined match offsets if we have no match
In case we're getting NO-MATCH "errors", we were still recomputing the
match offsets and taking decisions based on that, that might lead to
undefined behavior.

Avoid this by just returning early a FALSE result (but with no error) in
case there's no result to proceed on.

Fixes: #2741
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
1185a1304a gregex: Mark g_match_info_get_regex as transfer none
Since it had no explicit annotation, g-i was defaulting to transfer-full
while in this case the GRegex is owned by the GMatchInfo.
2022-09-12 13:55:39 +02:00
Aleksei Rybalkin
df66951b96 tests/regex: Add test for gtksourceview regression 2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
d639c4ec00 regex: Do not mix PCRE2 Compile, Match, Newline and BSR flags
As per the PCRE2 port we still used to try to map the old GRegex flags
(PCRE1 based) with the new PCRE2 ones, but doing that we were also
mixing flags with enums, leading to unexpected behaviors when trying to
get new line and BSR options out of bigger flags arrays.

So, avoid doing any mapping and store the values as native PCRE2 flags
internally and converting them back only when requested.

This fixes some regressions on newline handling.

Fixes: #2729
Fixes: #2688
Fixes: GNOME/gtksourceview#278
2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
d4966911e6 tests/regex: Actually check for match options changes 2022-09-12 13:55:39 +02:00
Marco Trevisan (Treviño)
23c1b401d8 tests/regex: Add debug strings for compile and match option flags
In case of failures they give a better info.
2022-09-12 13:55:39 +02:00
Mohammed Sadiq
3999badc1e gbacktrace: Don't truncate gdb output 2022-09-08 08:45:21 +05:30
Marco Trevisan (Treviño)
0618f5eb82 g_strsplit: Use a pre-allocated GArray when max_tokens is provided
In case max_tokens is provided, we can safely pre-allocate the GArray to
the max_tokens value plus one for the NULL terminating value.
2022-09-02 21:31:34 +02:00
Matthias Clasen
1df83acb87 mem: Document OOM behavior for allocations
For all the memory allocator APIS, document
that they terminate the program on failure.

This was so far only mentioned in the long description,
and in the docs for g_try_malloc(). And with gi-docgen
style docs, the long description is going away.
2022-08-19 08:29:36 -04:00
Luca Bacci
bf028b9176 Merge branch 'protect-calls-to-msvcrt-wspawne-with-a-mutex' into 'main'
GSpawn/Win32: Provide thread-safe wrappers for _wspawn*e functions

Closes #2509

See merge request GNOME/glib!2843
2022-08-03 04:49:50 +00:00
Christian Hergert
b62745fe8e gmain: close pidfd when finalizing GChildWatchSource
A file-descriptor was created with the introduction of pidfd_getfd() but
nothing is closing it when the source finalizes. The GChildWatchSource is
the creator and consumer of this FD and therefore responsible for closing
it on finalization.

The pidfd leak was introduced in !2408.

This fixes issues with Builder where anon_inode:[pidfd] exhaust the
available FD limit for the process.

Fixes #2708
2022-08-02 12:35:56 -07:00
Luca Bacci
477ff949e1 gspawn-win32: Provide thread-safe wrappers for _wspawn*e functions
_wspawn*e functions are not thread safe on the MSVCRT.dll and
the pre-2015 MSVC runtime DLLs (msvcrXXX.dll).
2022-08-02 18:47:05 +02:00
Luca Bacci
45bdeeddff GWin32AppInfo: Actually report the GPid in the GAppLaunchContext::launched signal
We need to pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_async,
otherwise the returned child_pid will always be 0.
2022-08-02 16:38:32 +02:00
Mamoru TASAKA
710ccee65c gregex: use correct size for pcre2_pattern_info
man pcre2_pattern_info says that the 3rd argument must
point to uint32_t variable (except for some 2nd argument value),
so correctly use it. Especially using wrong size can cause
unexpected result on big endian.

closes: #2699
2022-07-26 21:51:45 +09:00
Emmanuele Bassi
8f68c1e646 Rename G_MARKUP_PARSE_FLAGS_NONE
The prefix for GMarkupParseFlags enumeration members is G_MARKUP; this
means that G_MARKUP_PARSE_FLAGS_NONE gets split into
GLib.MarkupParseFlags.PARSE_FLAGS_NONE by the introspection scanner.

The `/*< nick=none >*/` trigraph attribute is a glib-mkenum thing, and
does not affect the introspection scanner; it would also only affect the
GEnumValue nickname, which is not used by language bindings to resolve
the name of the enumeration member. Plus, GMarkupParseFlags does not
have a corresponding GType anyway.
2022-07-25 22:30:22 +01:00
Aleksei Rybalkin
a2b5b9e906 gregex: add original test case for issue #2700 2022-07-25 16:57:06 +02:00
Aleksei Rybalkin
6535c77b00 gregex: do not set match and recursion limits on match context
These are not really necessary, and cause breakages (e.g. #2700).
pcre2_set_recursion_limit is also deprecated.

Fixes: #2700
2022-07-25 16:48:03 +02:00
Simon McVittie
6c3e52bb1d gmessages: Factor out _g_fd_is_journal into its own translation unit
I want to use this in gio-launch-desktop, but gio-launch-desktop
doesn't depend on GLib, so I can't just call g_log_writer_is_journald().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:54 +02:00
Simon McVittie
a4135b9652 assert-msg-test.py: Look for assert-msg-test relative to this script
When run as an installed-test, assert-msg-test generally won't be in
the PATH, but it will be in the same directory as the installed copy
of this script, so we can find it that way.

This fixes an installed-tests failure in Debian's autopkgtest
environment.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-24 16:33:12 +01:00
Marco Trevisan
58172a92bf Merge branch 'flag-reverse-docs' into 'main'
goption: Slightly improve the documentation for G_OPTION_FLAG_REVERSE

See merge request GNOME/glib!2830
2022-07-23 17:39:29 +00:00
Philip Withnall
55928d6ac0 Merge branch 'more-atomic-ops' into 'main'
Use atomic exchange operations more

See merge request GNOME/glib!2759
2022-07-23 11:35:08 +00:00
Aleksei Rybalkin
2c2e059cd3 gregex: use g_debug instead of g_warning in case JIT is not available
In case JIT is not available in pcre2 we printed warning about it. This
warning broke tests on systems which don't have JIT support in pcre2
(e.g. macos).
2022-07-22 20:29:07 +02:00
Aleksei Rybalkin
bcd8cb3e14 gregex: use G_REGEX_OPTIMIZE flag to enable JIT compilation
Since we ported gregex to pcre2, the JIT compiler is now available to be
used. Let's undeprecate G_REGEX_OPTIMIZE flag to control whether the JIT
compilation is requested, since using JIT is itself an optimization.
See [1] for details on its implementation in pcre2.

[1] http://pcre.org/current/doc/html/pcre2jit.html

Fixes: #566
2022-07-20 20:48:17 +00:00