Commit Graph

9191 Commits

Author SHA1 Message Date
Kleis Auke Wolthuizen
72d76922dc girepository: Fix static build under Windows
Properly define `GI_STATIC_COMPILATION` when static build is enabled.
Use `library()` instead of `shared_library()` to allow selecting static builds.
2024-02-21 12:38:40 +01:00
Philip Withnall
f3064e8a5c gutils: Make a variable const to avoid an unnecessary cast
And fix a typo in a comment. This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-13 15:22:04 +00:00
Philip Withnall
060a7c2740 Merge branch 'wip/smcv/issue3252' into 'main'
gdatetime: Fix ja_JA.eucjp expectations when eras are unsupported

Closes #3252

See merge request GNOME/glib!3920
2024-02-13 13:31:29 +00:00
Simon McVittie
9ceed6f0de gdatetime test: Produce more helpful output on mismatches
It's helpful for the assertion message to say what we were expecting and
what we actually got. It's also useful to have g_test_message()
diagnostics to indicate how far into the test we were.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-13 10:39:49 +00:00
Simon McVittie
342d6176e7 gdatetime: Exercise %c, %C format placeholders in ja_JP.eucjp
Previously we didn't test these at all, which made it hard to determine
whether %Ec, %EC had appropriate output on platforms where era-based
dates are unsupported. Now we do, and we can observe that on platforms
with no support for era-based dates, %c matches %Ec and %C matches %EC,
as desired.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-13 10:20:11 +00:00
Simon McVittie
988f4204a1 gdatetime: Fix ja_JA.eucjp expectations when eras are unsupported
I can't read Japanese, but these match the output of:

    env TZ=UTC LC_ALL=ja_JP.eucjp date -d2009-10-24T00:00:00Z '+%c' | iconv -f eucjp -t UTF-8
    env TZ=UTC LC_ALL=ja_JP.eucjp date -d2009-10-24T00:00:00Z '+%C' | iconv -f eucjp -t UTF-8

which seem like a reasonable thing to use as a reference.

According to Google Translate, 平成 refers to the Heisei era, which was
current during 2009, and seems unreasonable to expect as output on a
platform where era-based dates are unsupported.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3252
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-13 10:20:02 +00:00
Philip Withnall
1f9e44d623 glib: Install platform specific headers in a separate step
Maintain them in separate lists within `meson.build`. This makes no
functional difference at the moment, but will be used in an upcoming
commit to generate separate GIR files per platform.

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

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
e58abedf28 Revert "gwin32: Un-hide symbols when building GIR"
This reverts commit 50d432c77b.

The platform-specific headers of GLib and Gio are now introspected
separately, so the documentation for them can be built separately, and
this workaround is no longer needed.

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
d12a9f00d9 Merge branch 'unix-pipe-open-docs' into 'main'
glib-unix: Fix reference to FD_CLOEXEC in docs for g_unix_pipe_open()

See merge request GNOME/glib!3912
2024-02-09 21:59:59 +00:00
Philip Withnall
8300b52cbb Merge branch 'wip/smcv/closefrom' into 'main'
glib-unix: Add g_closefrom(), g_fdwalk_set_cloexec()

Closes #3247

See merge request GNOME/glib!3884
2024-02-09 14:06:52 +00:00
Philip Withnall
f9cbd07003 Merge branch 'wip/smcv/pipes' into 'main'
glib/tests/unix: Mostly pass O_CLOEXEC to g_unix_pipe_open()

See merge request GNOME/glib!3911
2024-02-09 13:48:02 +00:00
Philip Withnall
6dea98bac4 glib-unix: Fix reference to FD_CLOEXEC in docs for g_unix_pipe_open()
The docs for this should match the docs for `g_unix_open_pipe()`, which
it calls.

Inspired by !3911.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-09 13:10:42 +00:00
Simon McVittie
f4afed90e6 tests: Exercise g_fdwalk_set_cloexec() and g_closefrom()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 12:12:29 +00:00
Simon McVittie
82c9a4631d glib/tests/unix: Mostly pass O_CLOEXEC to g_unix_pipe_open()
Using FD_CLOEXEC here is now deprecated. Keep exactly one call with
FD_CLOEXEC, in test_pipe_fd_cloexec().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 11:15:28 +00:00
Simon McVittie
a7d5a6b69a gspawn: Simplify set_cloexec
The copy of this function that moved to glib-unix.c still needs to
implement the fdwalk-style interface, but this copy does not, allowing
us to turn it into a very simple syscall wrapper. Its remaining callers
never check for errors, and it never failed anyway, so remove the
returned value.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 10:57:12 +00:00
Simon McVittie
69c1a05ede glib-unix: Add g_closefrom(), g_fdwalk_set_cloexec()
These are the same as Linux `close_range (lowfd, ~0U, 0)` and
`close_range (lowfd, ~0U, CLOSE_RANGE_CLOEXEC)`, but portable.
Unlike some implementations of BSD closefrom(3), they are
async-signal-safe.

The implementations were moved from the GSpawn code, which already
needs all of this functionality anyway, with the exception of
set_cloexec() which was copied (leading to some minor duplication,
but it's very simple).

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3247
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 10:57:12 +00:00
Philip Withnall
e1d603bc3d gslice: Hide g_slice_debug_tree_statistics from introspection
It’s not useful and previously hasn’t been shown in the introspection
API.

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

Fixes: #3231
2024-02-09 10:08:00 +00:00
Philip Withnall
e9c94e8bf3 build: Remove private header files from Meson sources lists
They don’t need to be listed there in order to be built, and doing so
just means they get pulled into the `g-ir-scanner` command for building
`GLib-2.0.gir` and their contents end up being listed as public
introspectable API, which is not what we want.

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

Helps: #3231
2024-02-09 10:06:52 +00:00
Thomas Haller
5525672a5f build: avoid "-Werror=format-extra-args" warnings in detecting printf for gnulib
Otherwise, `CFLAGS='-Wall -Werror' meson build` fails detection with:

  Running compile:
  Working directory:  /data/src/glib/build/meson-private/tmpoozk2y4b
  Code:

  #include <stdio.h>
  #include <string.h>
  static char buf[100];
  static double zero = 0.0;
  int main ()
  {
    if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
        || (strcmp (buf, "       inf") != 0
            && strcmp (buf, "  infinity") != 0))
      return 1;
    return 0;
  }

  -----------
  Command line: `cc /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c -o /data/src/glib/build/meson-private/tmpoozk2y4b/output.exe -Werror -Wall -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c: In function 'main':
  /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c:8:21: error: too many arguments for format [-Werror=format-extra-args]
      8 |   if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
        |                     ^~~~~~~
  cc1: all warnings being treated as errors
  -----------
  Could not compile test file /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c: 1

  Checking if "printf supports the zero flag correctly" runs: DID NOT COMPILE
2024-02-07 20:40:59 +01:00
Thomas Haller
a91219f164 build: fix compiler warnings in gnulib printf meson build checks
Otherwise, `CFLAGS='-Wall -Werror' meson build` fails detection with:

  ...
    if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
      result |= 1;
    if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
      result |= 2;
    if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
        || buf[0] != '1')
      result |= 4;
    if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
        || buf[0] != '1')
      result |= 4;
    return result;
  }

  -----------
  Command line: `cc /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c -o /data/src/glib/build/meson-private/tmpu3dav6iy/output.exe -Wall -Werror -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c: In function 'main':
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:12:21: error: too many arguments for format [-Werror=format-extra-args]
     12 |   if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
        |                     ^~~~~~~~~~~~
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:14:21: error: too many arguments for format [-Werror=format-extra-args]
     14 |   if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
        |                     ^~~~~~~~~~~~
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:16:21: error: too many arguments for format [-Werror=format-extra-args]
     16 |   if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
        |                     ^~~~~~~~~~~
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:19:21: error: too many arguments for format [-Werror=format-extra-args]
     19 |   if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
        |                     ^~~~~~~~~~~
  cc1: all warnings being treated as errors
  -----------
  Could not compile test file /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c: 1
2024-02-07 14:46:57 +01:00
Thomas Haller
a65fa9a33f build: fix compiler warning in gl_cv_func_frexpl_works meson build check
Otherwise, `CFLAGS='-Wall -Werror' meson build` fails with:

  ...
  Command line: `cc ./glib/build/meson-private/tmp7iwplrgi/testfile.c -o ./glib/build/meson-private/tmp7iwplrgi/output.obj -c -O3 -Werror -Wall -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  ./glib/build/meson-private/tmp7iwplrgi/testfile.c: In function 'main':
  ./glib/build/meson-private/tmp7iwplrgi/testfile.c:83:21: error: unused variable 'y' [-Werror=unused-variable]
     83 |         long double y = frexpl (x, &exp);
        |                     ^
  cc1: all warnings being treated as errors
  -----------
  Checking if "frexpl prototype can be re-listed" compiles: NO

  glib/gnulib/meson.build:316:2: ERROR: Problem encountered: frexpl() is missing or broken beyond repair, and we have nothing to replace it with
2024-02-07 14:46:57 +01:00
Philip Withnall
b06107579c gtestutils: Reformat docs for g_test_queue_destroy()
Fix a typo in them and improve the formatting while I’m there.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-06 11:05:13 +00:00
Philip Withnall
9dad94e7e5 gtestutils: Ensure test_data is freed even if a test is skipped
It’s reasonable for the `main()` function in a test suite to pass
ownership of some test data to `g_test_add_data_func_full()`, along with
a `GDestroyNotify`, and rely on GTest to free the data after all tests
have been run.

Unfortunately that only worked if the test was run, and not skipped
before its test function was called. This could happen if, for example,
it had `/subprocess` in its path.

Fix that by always freeing the test data. This required reworking how
tests are skipped, slightly, to bring all the logic for that within
`test_case_run()`, so that it could always handle the memory management.

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

Helps: #3248
2024-02-06 11:02:24 +00:00
Philip Withnall
25e68476fa Merge branch 'garray_maxuint' into 'main'
garray: improve boundary checks

Closes #3240

See merge request GNOME/glib!3882
2024-02-05 18:34:14 +00:00
Tobias Stoeckmann
766bc75917 garray: Missing precondition checks
The function arguments index_ and length could lead to a sum which is
larger than G_MAXUINT, possibly leading to out of boundary accesses
in array_remove_range functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>

Fixes: #3240
2024-02-05 18:09:59 +01:00
Thomas Haller
10d4351ec9 gdataset: add code comment to g_datalist_get_data()
It's not obvious why we wouldn't use g_quark_try_string(). Add a code
comment that this is intentional and a reference for how to find out
more.

Also, fix typo in another code comment.
2024-02-05 16:49:10 +01:00
Thomas Haller
29314690c7 gdatalist: shrink the buffer when it becomes 75% empty
The amount of used memory should stay in relation to the number of
entries we have. If we delete most (75%) of the entries, let's also
reallocate the buffer down to 50% of its size.

datalist_append() now starts with 2 elements. This works together with
the shrinking. If we only have one entry left, we will shrink the buffer
back to size 2. In general, d->alloc is always a power of two (unless it
overflows after G_MAXUINT32/2, which we assume will never happen).

The previous buffer growth strategy of never shrinking is not
necessarily bad. It has the advantage to not require any checks for
shrinking, and it works well in cases where the amount of data actually
does not shrink (as we'd often expect).

Also, it's questionable what a realloc() to a smaller size really
brings. Is that really gonna help and will the allocator do something
useful?

Anyway. This patch introduces shrinking. The check for whether to shrink
changes from `if (d->len == 0)` to `if (d->len <= d->alloc / 4u)`, which
is probably cheap even if most of the time we don't need to shrink. For
most cases, that's the only change that this patch brings. However, once
we find out that 75% of the buffer are empty, calling realloc() seems a
sensible thing to do.
2024-02-05 13:34:31 +01:00
Thomas Haller
6c0d4c884f gdatalist: rework g_data_remove_internal() to use datalist_shrink()
The main point here is to reuse datalist_remove() and datalist_shrink().
Especially, datalist_shrink() will become more interesting next, when it
actually shrinks the buffer.

Also, I find the previous implementation with "data_end" confusing.
Instead, only use index "i_data" to iterate over the data.
2024-02-02 19:56:26 +01:00
Thomas Haller
927075277c gdatalist: extract helper function for removing element
Extract helper functions datalist_remove() and datalist_shrink(). This
is to reduce duplicate code, but also to have a default way how to do
this.

In particular, later datalist_shrink() might do more aggressive
shrinking. We need to have that code in one place.
2024-02-02 19:56:26 +01:00
Thomas Haller
dbae6b3484 gdatalist: rework g_datalist_clear() to return early
g_datalist_unlock() is probably faster than g_datalist_unlock_and_set().
Move the "if (data)" check (that we anyway had) earlier, so we can
call g_datalist_unlock() and return early.
2024-02-02 19:56:26 +01:00
Thomas Haller
759ebf3663 gdatalist: remove restriction of number of keys in g_datalist_id_remove_multiple()
If too many keys are requested, they temporary buffer is allocated
on the heap. There is no problem in principle, to remove more than
16 keys.

Well, the problem is that GData tracks entries in a linear list, so
performance will degrade when it grows too much. That is a problem,
and users should be careful to not add unreasonably many keys. But it's
not the task of g_datalist_id_remove_multiple() to decide what is
reasonable.

This limitation was present from the beginning, in commit 0415bf9412
('Add g_datalist_id_remove_multiple'). It's no longer necessary since
commit eada6be364 ('gdataset: cleanup g_data_remove_internal()').
2024-02-02 19:56:26 +01:00
Thomas Haller
48a1d8c695 dataset/tests: add test adding many queue data and remove them 2024-02-02 19:27:44 +01:00
Philip Withnall
3f4e6ddcd8 Merge branch 'thorough-tests-in-ci' into 'main'
build: Add thorough test setup

See merge request GNOME/glib!3838
2024-02-02 14:33:22 +00:00
Philip Withnall
2638f97b3e Merge branch 'th/weak-ref-lock-2' into 'main'
[th/weak-ref-lock-2] gobject: use per-object bit-lock instead of global RWLock for GWeakRef

Closes #743

See merge request GNOME/glib!3834
2024-01-31 16:51:50 +00:00
Thomas Haller
0c06a4b7a0 glib: add internal g_datalist_id_update_atomic() function
GDataSet is mainly used by GObject. Usually, when we access the private
data there, we already hold another lock around the GObject.

For example, before accessing quark_toggle_refs, we take a
OPTIONAL_BIT_LOCK_TOGGLE_REFS lock. That makes sense, because we anyway
need to protect access to the ToggleRefStack. By holding such an
external mutex around several GData operations, we achieve atomic
updates.

However, there is a (performance) use case to update the qdata
atomically, without such additional lock. The GData already holds a lock
while updating the data. Add a new g_datalist_id_update_atomic()
function, that can invoke a callback while holding that lock.

This will be used by GObject. The benefit is that we can access the
GData atomically, without requiring another mutex around it.

For example, a common pattern is to request some GData entry, and if
it's not yet allocated, to allocate it. This requires to take the GData
bitlock twice. With this API, the callback can allocate the data if no
entry exists yet.
2024-01-31 17:30:28 +01:00
Thomas Haller
0adb1c24d7 glib: return const pointer from glib__private__()
also, make the global variable "static const". That may allow the linker
to place the variable into read-only memory, so we are a bit more confident
that it cannot be modified.
2024-01-29 16:05:29 +01:00
Thomas Haller
6955c25e85 glib: use g_strdup() in g_ascii_strdown(),g_ascii_strup()
g_strndup() internally uses strncpy(), while g_strdup() uses memcpy().
Most likely, memcpy() is faster.

Instead of strlen()+g_strndup(), use  g_strdup() as we don't need the
length.
2024-01-25 20:11:48 +01:00
Philip Withnall
96b1298871 Merge branch 'improve-documentation' into 'main'
gprintf/gstrfuncs: Improve and port doc comments to gi-docgen

See merge request GNOME/glib!3807
2024-01-25 12:16:57 +00:00
velsinki
66cd331172 gstrfuncs: Improve and port doc comments to gi-docgen
This fixes many things from the port to gi-docgen, but also improves
documentation more generally.

Main improvements/fixes:
- Fix links to functions, constants, etc.
- Rewrite code syntax to work with Markdown
- Reduce indentation (do not indent by 4 to prevent code blocks)
- Remove redundant text such as "can be NULL" or "should be freed"
- Move text from large return info texts to main function text
- Remove periods at the end of parameter and return descriptions
- Do not capitalize the first word of a parameter or return description
- Try to improve consistency between docs for similar functions
- Convert %TRUE and %FALSE into true and false
- Convert other uses of `%` and `#` into inline code

Helps: #3037
2024-01-25 11:35:48 +00:00
velsinki
a834b8b038 gstrfuncs: Add missing (array) annotations to GStrv comparison functions 2024-01-25 11:35:12 +00:00
velsinki
dc7331f4fb gstrfuncs: Add missing (optional) annotation to g_str_tokenize_and_fold() 2024-01-25 11:33:09 +00:00
velsinki
2d5955c4f3 gstrfuncs: Add missing (array) annotation to g_strv_length() 2024-01-25 11:32:56 +00:00
velsinki
b869908f16 gstrfuncs: Add missing (array) annotations to g_strdupv() and g_strjoinv() 2024-01-25 11:29:52 +00:00
velsinki
8689a1f8b7 gstrfuncs: Add missing (nullable) annotations to g_strndup() 2024-01-25 11:25:09 +00:00
velsinki
2d5f608454 gstrfuncs: Add missing (transfer) and (nullable) annotations to g_memdup() 2024-01-25 11:22:54 +00:00
velsinki
16ea531ecb gstrfuncs: Add missing (array) annotation to g_strfreev() 2024-01-25 11:20:00 +00:00
velsinki
8d2d12bd52 gprintf: Port doc comments to gi-docgen
Fixes broken links, and removes `%` and `#` notation in favor of inline
code, and limits indentation to two to prevent accidental formatting.

Fixes some style issues too, mainly removing periods at the end of
parameter and return descriptions.

Also removes trailing whitespace from the doc comments.

Helps: #3037
2024-01-25 11:19:23 +00:00
velsinki
2b22befc4f gprintf: Add missing (out) annotation to g_vasprintf() 2024-01-25 11:19:23 +00:00
Luca Bacci
f7c4825d91 Fix build with introspection on Windows 2024-01-24 18:16:58 +01:00
Philip Withnall
b8fba4ddb4 Merge branch 'freebsd-iconv' into 'main'
gconvert: match GNU iconv behaviour on FreeBSD

See merge request GNOME/glib!3824
2024-01-22 18:40:03 +00:00
Ting-Wei Lan
ec780d0d4a Use the FreeBSD cgit URL 2024-01-22 15:39:33 +00:00
Philip Withnall
aee343fe5c Merge branch 'auto-lock' into 'main'
Add G_*_AUTO_LOCK macros

Closes #3223

See merge request GNOME/glib!3822
2024-01-21 21:02:35 +00:00
Jordan Petridis
a011dd0048 docs: Fix member names of GLib.LogLevelFlags 2024-01-19 19:04:04 +02:00
Simon McVittie
6da5e6a327 gvarianttype: Fix typos
Saying that a GtkWidget is a GtkWidget is trivially true, but not the
point we were trying to make here.

Fixes: b5c07063 "docs: Use code for class names in links"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-19 11:53:00 +00:00
Emmanuele Bassi
4ff4f073a4 Merge branch 'altiera/docs' into 'main'
docs: Fix links to symbols outside the allowed namsepace

See merge request GNOME/glib!3809
2024-01-18 18:35:21 +00:00
Philip Withnall
5537ee4d7f tests: Drop a duplicate test from testing tests
The test cancellation timeout was being tested twice, once only when run
with `-m thorough`. Seems a bit pointless.

Merge the two tests and use the smaller timeout values from the two, so
the test suite doesn’t run any more slowly than it did.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-18 17:22:09 +00:00
Philip Withnall
82a6c54135 tests: Fix running mapping test with -m argument
`g_test_init()` needs to be called before custom command line handling
so it has a chance to strip out the arguments it handles.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-18 17:22:09 +00:00
Philip Withnall
615060d872 tests: Drop some unnecessary messages from mapping test
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-18 17:22:09 +00:00
Philip Withnall
64e630e132 tests: Disable crash reporting in g_error() path in testing-helper
This avoids four coredumps being processed for every run of the
`testing` unit tests (which test `GTest`).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-18 15:23:53 +00:00
Xavier Claessens
9e8f07b156 Add G_*_AUTO_LOCK macros
It is common to declare a mutex locker variable and to not use it in the
scope. That causes clang to warn about unused variable which is not
entirely true since the cleanup function IS the intended usage.

Work around that issue with a new macro that uses G_GNUC_UNUSED and
has the extra advantage of being less verbose.

Fixes: #3223.
2024-01-17 08:57:12 -05:00
Alex Richardson
859748eccd gconvert: match GNU iconv behaviour on FreeBSD
FreeBSD iconv by default handles input characters that are not
representable in the destination character set by emitting a replacement
character such as '?'. While this appears to be the POSIX mandated
behaviour it does not match GNU behaviour and causes the gconvert test
to fail in the `test_one_half` testcase. Fortunately FreeBSD provides a
iconvctl flag to request this behaviour to match GNU iconv.

See https://github.com/freebsd/freebsd-src/commit/7c5b23111c5fd199204
2024-01-16 10:59:12 -08:00
Marco Trevisan
1b32e72073 Merge branch 'posix-memalign-zero' into 'main'
gvariant-core: Don’t call posix_memalign() with size==0

See merge request GNOME/glib!3831
2024-01-16 18:52:21 +00:00
Philip Withnall
1e0cec289c tests: Avoid calling malloc(0) in gvariant tests
Its behaviour is implementation-defined according to POSIX
(https://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html),
and we’d quite like it to consistently return `NULL` for a zero-size
allocation.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-01-16 16:55:08 +00:00
Philip Withnall
f70b3a91d3 Merge branch 'th/g-pointer-bit-lock-ext' into 'main'
[th/g-pointer-bit-lock-ext] glib: add g_pointer_bit_unlock_and_set() and g_pointer_bit_lock_mask_ptr()

See merge request GNOME/glib!3802
2024-01-16 13:43:54 +00:00
Thomas Haller
a9ed0e2491 gbitlock: factor out bit_lock_contended_class() to avoid duplicated code 2024-01-16 12:50:31 +01:00
Thomas Haller
5e1875dbdc gdataset: factor out common code for find/append of key
The duplication is cumbersome. Factor out common pieces to finding the
data by key and appending a new data.
2024-01-16 12:50:31 +01:00
Thomas Haller
f6b24a0a20 gdataset: use g_pointer_bit_lock_and_get() for g_datalist_lock_and_get() 2024-01-16 12:50:31 +01:00
Thomas Haller
5609370de9 gbitlock: add g_pointer_bit_lock_and_get()
Usually, after g_pointer_bit_lock() we want to read the pointer that we
have. In many cases, when we g_pointer_bit_lock() a pointer, we can
access it afterwards without atomic, as nobody is going to modify the
pointer then.

However, gdataset also supports g_datalist_set_flags(), so the pointer
may change at any time and we must always use atomics to read it. For
that reason, g_datalist_lock_and_get() does an atomic read right after
g_pointer_bit_lock().

g_pointer_bit_lock() can easily access the value that it just set. Add
g_pointer_bit_lock_and_get() which can return the value that gets set
afterwards.

Aside from saving the second atomic-get in certain scenarios, the
returned value is also atomically the one that we just set.
2024-01-16 12:50:31 +01:00
Thomas Haller
abe4b4e7d8 gdataset: add and use helper g_datalist_lock_and_get()
In all cases after taking the lock with g_datalist_lock(), we also
get the pointer. And it hardly makes sense otherwise.

Replace g_datalist_lock() by g_datalist_lock_and_get() which does
both steps in one.
2024-01-16 12:26:46 +01:00
Thomas Haller
eada6be364 gdataset: cleanup g_data_remove_internal()
- only use gnewa0() for up to 400 bytes (arbitrarily chosen as
  something that is probably small enough to cover most small tasks
  while fitting easily on the stack). Otherwise fallback to g_new0().

- don't do intermediate G_DATALIST_SET_POINTER(). Set to NULL
  afterwards with g_datalist_unlock_and_set().

- move the g_free(d) after releasing the lock on datalist.
2024-01-16 12:26:46 +01:00
Thomas Haller
435aa01158 gdataset: update pointers at end of g_datalist_id_replace_data()
- when setting datalist to NULL, do it at the end with
  g_datalist_unlock_and_set() to avoid the additional atomic
  operations.
- when freeing the old "d", do that after releasing the bit
  lock.
2024-01-16 12:25:13 +01:00
Thomas Haller
a426410919 gdataset: use guintptr instead of gsize for pointer mangling
The previous code was in practice correct.

  (((guintptr) ptr) | ((gsize) mask))

works even if gsize is smaller than guintptr. And while the C standard
only guarantees that cast between uintptr_t and void* works, on
reasonable compilers it works to directly cast uintptr_t to GData*.

Still, no need for such uncertainty. Just be clear about the involved
types (use guintptr throughout) and cast first to (gpointer).
2024-01-16 12:16:42 +01:00
Thomas Haller
3f34a49ee9 gdataset: simplify g_dataset_destroy_internal() 2024-01-16 12:16:42 +01:00
Thomas Haller
e931162348 gdataset: inline g_datalist_clear_i() in g_dataset_destroy_internal()
g_datalist_clear_i() had only one caller, altough the code comment made
it sound as if in the past there were more.

A function that has only one caller, and then needs a code comment to
explain the context in which it is called, makes the code more complicated
than necessary.

Especially since the function expects to be called with a global lock
held, and then unlocks and relocks. Spreading such things to another
function (which is only used once) makes code harder to follow.

Inline the function, so that we can see all the (trivial) code at one place.
2024-01-16 12:16:42 +01:00
Thomas Haller
8439b589ec gdataset: use g_datalist_unlock_and_set() in gdataset
This saves an additional atomic set.

Also, changing the pointer before the unlock can awake a blocked thread,
but at this point, the lock is still held (and the thread may need to
sleep again). This can be avoided.
2024-01-16 12:16:42 +01:00
Thomas Haller
c4c76d77cb gbitlock: add g_pointer_bit_unlock_and_set() and g_pointer_bit_lock_mask_ptr()
The existing g_pointer_bit_lock() and g_pointer_bit_unlock() API
requires the user to understand/reimplement how bits of the pointer get
mangled. Add helper functions for that.

The useful thing to do with g_pointer_bit_lock() API is to get/set
pointers while having it locked. For example, to set the pointer a user
can do:

    g_pointer_bit_lock (&lockptr, lock_bit);
    ptr2 = set_bit_pointer_as_if_locked(ptr, lock_bit);
    g_atomic_pointer_set (&lockptr, ptr2);
    g_pointer_bit_unlock (&lockptr, lock_bit);

That has several problems:

- it requires one extra atomic operations (3 instead of 2, in the
  non-contended case).

- the first g_atomic_pointer_set() already wakes blocked threads,
  which find themselves still being locked and needs to go back to
  sleep.

- the user needs to re-implement how bit-locking mangles the pointer so
  that it looks as if it were locked.

- while the user tries to re-implement what glib does to mangle the
  pointer for bitlocking, there is no immediate guarantee that they get
  it right.

Now we can do instead:

  g_pointer_bit_lock(&lockptr, lock_bit);
  g_pointer_bit_unlock_and_set(&lockptr, lock_bit, ptr, 0);

This will also emit a critical if @ptr has the locked bit set.
g_pointer_bit_lock() really only works with pointers that have a certain
alignment, and the lowest bits unset. Otherwise, there is no space to
encode both the locking and all pointer values. The new assertion helps
to catch such bugs.

Also, g_pointer_bit_lock_mask_ptr() is here, so we can do:

  g_pointer_bit_lock(&lockptr, lock_bit);
  /* set a pointer separately, when g_pointer_bit_unlock_and_set() is unsuitable. */
  g_atomic_pointer_set(&lockptr, g_pointer_bit_lock_mask_ptr(ptr, lock_bit, TRUE, 0, NULL));
  ...
  g_pointer_bit_unlock(&lockptr, lock_bit);

and:

  g_pointer_bit_lock(&lockptr, lock_bit);
  /* read the real pointer after getting the lock. */
  ptr = g_pointer_bit_lock_mask_ptr(lockptr, lock_bit, FALSE, 0, NULL));
  ...
  g_pointer_bit_unlock(&lockptr, lock_bit);
2024-01-16 12:16:42 +01:00
Philip Withnall
635f8d43eb gvariant-core: Don’t call posix_memalign() with size==0
While glibc is fine with it (and returns a `NULL` pointer), technically
it’s implementation-defined behaviour according to POSIX, so it’s best
avoided.

See
https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html.

In particular, valgrind will warn about it, which is causing failures of
the gdbus-codegen tests when valgrind is enabled. For example,
https://gitlab.gnome.org/GNOME/glib/-/jobs/3460673 gives
```
==15276== posix_memalign() invalid size value: 0
==15276==    at 0x484B7BC: posix_memalign (vg_replace_malloc.c:2099)
==15276==    by 0x49320B2: g_variant_new_from_bytes (gvariant-core.c:629)
==15276==    by 0x4931853: g_variant_new_from_data (gvariant.c:6226)
==15276==    by 0x4B9A951: g_dbus_gvalue_to_gvariant (gdbusutils.c:708)
==15276==    by 0x41BD15: _foo_igen_bat_skeleton_handle_get_property (gdbus-test-codegen-generated.c:13503)
==15276==    by 0x41BFAF: foo_igen_bat_skeleton_dbus_interface_get_properties (gdbus-test-codegen-generated.c:13582)
…
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3228
2024-01-16 11:04:44 +00:00
Philip Withnall
68d5a0bef2 Merge branch '3037-log-docs' into 'main'
gmessages: Port all doc comments to gi-docgen

See merge request GNOME/glib!3801
2024-01-16 08:59:32 +00:00
Alex Richardson
81332ab903 array-test: Don't assume sizeof(void*)==sizeof(gsize)
Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2024-01-15 16:30:47 -08:00
Philip Withnall
39f0b74a66 Merge branch 'syslog' into 'main'
gmessages: add syslog support

Closes #3207

See merge request GNOME/glib!3791
2024-01-15 21:59:19 +00:00
Philip Withnall
166f04a57f Merge branch 'gvariant-parse-detail' into 'main'
gvariant-parser: Mention annotated types

See merge request GNOME/glib!3811
2024-01-15 17:24:53 +00:00
Philip Withnall
0c9fe8156a Merge branch 'improve-set_str-documentation' into 'main'
gstrfuncs: Improve and port g_set_str() docs to gi-docgen

See merge request GNOME/glib!3810
2024-01-15 17:09:17 +00:00
Emmanuele Bassi
b5c07063c3 docs: Use code for class names in links
So that they fit with the documentation guidelines, and with the links
generated by gi-docgen.
2024-01-15 14:43:53 +00:00
Guido Günther
13a2ea7dd8 gvariant-parser: Fix links to gvariant-format doc
Also escape some function names
2024-01-15 14:39:46 +00:00
Guido Günther
d025a7f5b3 gvariant-parser: Mention annotated types
g_variant_parse() supports g_variant_printf()s type annotations which
can be needed e.g. in detailed action names.

Reference: https://gitlab.gnome.org/GNOME/gtk/-/issues/6303#note_1958300
2024-01-15 14:39:17 +00:00
Simon McVittie
6de98cc255 gdatetime: Ignore %E modifier on 64-bit big-endian for the moment
This doesn't appear to work reliably on s390x and ppc64, returning
the results that were expected without %E or intermittently crashing.
It seems that on little-endian 64-bit, the intptr_t returned by the
undocumented _NL_TIME_ERA_NUM_ENTRIES correctly has the number of entries
in its low-order half (at the time of writing, 0x0000'0000'0000'000b for
Japan), but on big-endian 64-bit, it has the number of entries in its
high-order half instead (for example 0x0000'000b'0000'0000 for Japan),
with the low-order half being all-zero or possibly uninitialized.

Making this reliable will require some sort of defined API from glibc.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/3225
Bug-Debian: https://bugs.debian.org/1060735
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-15 14:18:40 +00:00
Emmanuele Bassi
88251e63bb gir: Hide pthread types in deprecated GThread structures
We only care about the introspection data for documentation purposes;
the GStaticMutex and GStaticRecMutex types are long since deprecated,
and they cannot be used from language bindings anyway, so their size is
immaterial.

Fixes: #3222
2024-01-15 12:39:36 +00:00
Marco Trevisan
38f5ba3c2f Merge branch 'docs-typo-fix' into 'main'
Fix typo in GPOINTER_TO_SIZE documentation

See merge request GNOME/glib!3814
2024-01-10 13:37:39 +00:00
Jordan Petridis
3f9f5c1420 docs: Fix links to symbols outside the allowed namsepace
Use markdown links for anything that the docs don't depend upon,
like gtk, pixbuf, etc
2024-01-09 21:24:22 +02:00
Alex Richardson
7ed0fa2120 Fix typo in GPOINTER_TO_SIZE documentation 2024-01-09 08:55:32 -08:00
velsinki
51fc82a567 gstrfuncs: Improve and port g_set_str() docs to gi-docgen
Fixes link and code block and includes code syntax.

Improves documentation to be more in line with the developer guidelines.
2024-01-09 16:37:51 +01:00
Jordan Petridis
d2e6892996 glib/deprecated: Skip all the deprecated gthread api
Previously, the girs and typelibs generated from gobject-introspection
ommited the deprecated apis, however we want them annotated for
documentation purposes.

Skip the deprecated gthead api so they do not make it into the
typelibs which caused problems as not all the symbols exist.

See https://gitlab.gnome.org/GNOME/gjs/-/issues/595
2024-01-08 12:01:41 +02:00
Yegor Yefremov
c8437611f0 gmessages: add syslog support
Introduce g_log_writer_syslog() that is suitable for use as a
GLogWriterFunc and sends the log message to the syslog daemon.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2024-01-05 21:39:25 +01:00
Thomas Haller
a12f0731dd glib: add internal macro G_THREAD_LOCAL for support for thread local storage
_Thread_local is also C11, so possibly other compilers would also support
it.

However, since not *all* compilers support it, it can anyway only be
used as optimization and conditional asserts. As such, the current
detection based on __GNUC__ to only support gcc (and clang) is good
enough.
2024-01-04 16:32:09 +01:00
Philip Withnall
56ea637240 gmessages: Port all doc comments to gi-docgen
This was done manually, but the changes are very repetitive. There are
some minor rewordings/formatting tweaks included. The bulk of the
changes are to the linking syntax.

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

Helps: #3037
2024-01-03 15:18:19 +00:00
Philip Withnall
4663307374 Merge branch 'datetime-docs' into 'main'
gdatetime: Fix title of documentation comment

See merge request GNOME/glib!3789
2024-01-03 13:47:22 +00:00
Kryggird
09de26185e Account for cpu affinity in g_get_num_processors 2023-12-22 16:11:45 +00:00
Philip Withnall
994bf21d9d gdatetime: Fix title of documentation comment
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-12-22 14:48:30 +00:00
Philip Withnall
833d3fb6cf Merge branch 'file-uri-cleanup' into 'main'
glocalvfs: Remove unnecessary and buggy code

See merge request GNOME/glib!3776
2023-12-21 12:42:27 +00:00
Colomban Wendling
5790ce14e8 tests: Test file:// URIs with both query and fragment 2023-12-20 19:23:40 +01:00
Xavier Claessens
a4edf1e3ae GDateTime: Add usec precision API for unix time 2023-12-20 07:48:10 -05:00
Philip Withnall
4608b87469 Merge branch 'wryun-gregex-handle-multiple-failed-optimise-matches-with-fallback' into 'main'
gregex: clean up usage of _GRegex.jit_status

Closes #2824

See merge request GNOME/glib!3750
2023-12-18 11:23:56 +00:00
James Haggerty
71ea08d5fa gregex: clean up usage of _GRegex.jit_status 2023-12-18 11:23:56 +00:00
Philip Withnall
00b75eb95c gerror: Fix an old allow-none annotation
It’s now best described as both nullable and optional.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-12-14 01:26:42 +00:00
Pablo Correa Gómez
2b4e667209
glit: tests: enable regex test under musl
This was an alpine packaging problem, that is no fixed in the new
release

Fixes #3159
2023-12-08 17:28:10 +01:00
António Fernandes
c9cd385b17 hash: Explicitly annotate key in iter_next as nullable
There is no reason for key and value to have different annotations.
Both may return NULL as a valid value.

gpointer typed parameters are nullable by convention, so there is
no change here. The (nullable) annotation is just for humans really.
2023-12-04 09:53:35 +00:00
Philip Withnall
58208c4ace gvarianttype: Add a missing argument name
To make it match its definition and documentation comment. This fixes a
g-ir-scanner warning.

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

Helps: #3037
2023-11-29 12:03:34 +00:00
Philip Withnall
81d96f5898 gmarkup: Add a missing (element-type) annotation
Fixes a g-ir-scanner warning.

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

Helps: #3037
2023-11-29 12:03:15 +00:00
Philip Withnall
02725b9bbd ghashtable: Add various missing (transfer) annotations
Fixes some g-ir-scanner warnings.

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

Helps: #3037
2023-11-29 12:02:49 +00:00
Philip Withnall
c7dfd218ea gerror: Add missing (scope forever) annotations
Extended error domains can never be unregistered, so these closures
have to be around forever.

Fixes some g-ir-scanner warnings.

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

Helps: #3037
2023-11-29 12:02:04 +00:00
Philip Withnall
c1547f62bc gbytearray: Add missing (transfer) annotations
`GByteArray` is a bit odd in that it allows call-chaining. All the
instances of that were missing a `(transfer none)` annotation though.

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

Helps: #3037
2023-11-29 12:01:12 +00:00
Philip Withnall
8f08c1a038 gthread: Make some argument names match up
This fixes a warning from g-ir-scanner as the declaration and
documentation comment didn’t match.

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

Helps: #3037
2023-11-29 12:00:35 +00:00
Philip Withnall
f14cd8de14 gcompletion: Make argument names match up
This fixes some warnings from g-ir-scanner.

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

Helps: #3037
2023-11-29 12:00:14 +00:00
Philip Withnall
d07c59ed4e glib: Add (scope call) to a load of sort/equal callbacks
This fixes a load of g-ir-scanner warnings.

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

Helps: #3037
2023-11-29 11:59:47 +00:00
Philip Withnall
8ee00cbad8 gdatetime: Disable ERA support on platforms which don’t support this
So far, that’s BSD: it supports `nl_langinfo()`, but not `ERA`.

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

Helps: #3119
2023-11-28 23:56:22 +00:00
Philip Withnall
9eda0b2fcd gdatetime: Fix typo in comment
This was pointed out in the review for !3696 but owing to a mistake by
me, the fix was not included in the version of the MR which was merged.

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

Helps: #3119
2023-11-28 23:14:40 +00:00
Philip Withnall
c8e3302007 gdatetime: Fix copyright/author information on recent GDateTime changes
I wrote the changes before clarifying the copyright status of my
contract with the GNOME Foundation, and forgot to update them.

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

Helps: #3119
2023-11-28 23:13:27 +00:00
Philip Withnall
517a3ac861 tests: Set locale to C.UTF-8 in datetime tests
It was previously set (by default) to `C`, so this commit doesn’t change
the locale behaviour of the tests, but does ensure that messages printed
by the tests are correctly formatted in UTF-8 rather than transliterated
to ASCII.

That makes interpreting test output easier.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-28 19:32:03 +00:00
Philip Withnall
09fe2aa78d gdatetime: Fix a minor leak on changing locale
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-28 19:32:03 +00:00
Philip Withnall
454064f82d gdate: Fix some typos in a documentation comment
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-28 19:32:03 +00:00
Philip Withnall
df4aea7620 gdatetime: Add support for %E modifier to g_date_time_format()
The `%E` modifier causes dates to be formatted using an alternative era
representation for years. This doesn’t do anything for most dates, but
in locales such as Thai and Japanese it causes years to be printed using
era names.

In Thai, this means the Thai solar calendar
(https://en.wikipedia.org/wiki/Thai_solar_calendar). In Japanese, this
means Japanese era names
(https://en.wikipedia.org/wiki/Japanese_era_name).

The `%E` modifier syntax follows what’s supported in glibc — see
nl_langinfo(3).

Supporting this is quite involved, as it means loading the `ERA`
description from libc and parsing it.

Unit tests are included.

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

Fixes: #3119
2023-11-28 19:32:02 +00:00
Philip Withnall
2c4a0c83e1 docs: Drop the regex-syntax page
Point people to the official PCRE documentation instead, which is going
to be more up to date. This saves us periodically having to copy in and
reformat the PCRE documentation.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
6a22d58f6b docs: Move the types SECTION
Move it to a mega separate file.

This has been a journey.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
33c10e8711 docs: Move the windows SECTION
Move it to a separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
3532e3ca1c docs: Move the warnings SECTION
Move it to a separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
877b0affb6 docs: Move the numerical SECTION
Move it to a separate Markdown file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
3957b47e59 docs: Move the checkedmath SECTION
Move it to a separate Markdown file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
b93e35dc17 docs: Move the datalist and dataset SECTIONs
Move them to a separate page as they don’t really have a ‘class’ struct
each to hang docs off.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
790131687c docs: Move the unix SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
244721baf9 docs: Move the misc_utils SECTION
Move it to a separate page, with a massive great list of all the misc
utils. Not a great documentation page, but equivalent to what we had
before, and it can be improved in future.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
74de872bb9 docs: Move the spawn SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
6dca578f9d docs: Move the memory SECTION
Move it to a separate page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
cbbd06fee7 docs: Drop the SECTION for tracing
All this API is internal to GLib, so the section was never actually
exposed in the public API documentation. Keep the documentation, just
don’t tag it as a SECTION.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
25a4205d9d docs: Move the ghostutils SECTION
Sadly, this is about hostnames rather than ghosts. 😞

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
425731f766 docs: Move the string_utils SECTION
Move it to a mega separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
cf52727f03 docs: Move the shell SECTION
Move it to a separate file.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
214853d6df docs: Move the GVariant SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
229b76a388 docs: Move the version SECTION
Move it to a separate documentation file, since most of what’s covered
isn’t introspectable.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
194db3f096 docs: Move the GVariantType SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
359c1034e0 docs: Move the GUuid SECTION
Move it to a separate page as there’s no public struct to hang the
docs off.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
be783fdc2a docs: Move the GUri SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
43588fcdd9 docs: Move the grand SECTION
Move it to a separate page so the difference between `g_rand_*()` and
`g_random_*()` can be explained.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
8179688c07 docs: Move the GTrashStack SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
1625c24d58 docs: Drop the hooks SECTION
It was one paragraph which mentioned `GHookList` and `GHook`, both of
which have their own adequate documentation sections.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
158ec5be34 docs: Move the gfileutils SECTION
Move it to a separate page so more detail can be provided about all the
groups of API.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
c850d25d67 docs: Move the gatomic SECTION
Move it to a standalone page.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
ac91b8f4a2 docs: Move the base64 SECTION
Move it to a separate file as there is no struct to hang the docs off.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
552f62a059 docs: Move the threads-deprecated SECTION
Move it to a separate page so an overview of the deprecated threading
API can be given.

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

Helps: #3037
2023-11-28 13:52:05 +00:00
Philip Withnall
f8122da6c9 Merge branch 'migrate-to-gi-docgen13' into 'main'
gwin32: Un-hide symbols when building GIR

See merge request GNOME/glib!3723
2023-11-28 13:49:42 +00:00
Philip Withnall
8f6f382940 Merge branch 'test-trap-subprocess-envp' into 'main'
gtestutils: Add g_test_trap_subprocess_with_envp() for testing envs

See merge request GNOME/glib!3721
2023-11-28 11:49:11 +00:00
Philip Withnall
e4fe837bae Merge branch 'migrate-to-gi-docgen12' into 'main'
gdir, gstrvbuilder: Add refcounting support and a boxed type

See merge request GNOME/glib!3722
2023-11-28 11:47:11 +00:00
Matthias Clasen
f79c53f953 gspawn: Stop spewing debug messages
My GTK testlogs are filled with

GLib-DEBUG: g_unix_open_pipe() called with FD_CLOEXEC; please migrate to using O_CLOEXEC instead

Lets take the hint, and migrate to using O_CLOEXEC.
2023-11-27 21:03:49 -05:00
Philip Withnall
2c4be841d7 tests: Fix string test failure on BSDs
As with `test-printf`, the `vasprintf()` placeholder checks on BSDs
(including macOS) are less strict than on Linux (glibc), so the expected
critical message is not seen.

Change the test to not expect it on BSDs.

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

Helps: #3187
2023-11-27 13:26:51 +00:00
Philip Withnall
707ae4bd79 gstring: Add critical warning to g_string_append_vprintf()
It was previously possible for this to silently fail, which isn’t great
for program correctness. Instead, raise a critical warning so the
programmer knows to either validate their Unicode inputs, or fix their
format placeholders.

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

Helps: #3187
2023-11-27 12:20:50 +00:00
Philip Withnall
c56bc6d8d9 gstrfuncs: Add missing annotations to g_strdup_vprintf()
It’s possible for the function to fail for the same reasons
`g_vasprintf()` would fail.

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

Helps: #3187
2023-11-27 12:20:50 +00:00
Philip Withnall
3c6052f318 gprintf: Fix invalid size allocation in g_vasprintf()
As per the previous commit, it’s possible for
`g_printf_string_upper_bound()` to return an error. We need to catch and
handle that error in `g_vasprintf()` to avoid it trying to write to a
`NULL` string allocation and crashing.

So, call `g_vsnprintf()` directly instead of calling
`g_printf_string_upper_bound()`, so that the error case can be handled.

There was already a test for some of this behaviour
(`test_vasprintf_invalid_format_placeholder()`). Because it tested an
invalid format string, the `_g_vsprintf()` call bailed out before
checking whether the buffer it had been passed was `NULL`. The new test
has a valid format string, but an invalid arg.

When running the tests locally, I have disabled the `USE_SYSTEM_PRINTF`
and `HAVE_VASPRINTF` code paths in `g_vasprintf()`.

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

Fixes: #3187
2023-11-27 12:20:12 +00:00
Philip Withnall
e2cd0962c2 gmessages: Document error case for g_printf_string_upper_bound()
Spotted in https://gitlab.gnome.org/GNOME/glib/-/issues/3187.

In an ideal world, this API would have been designed with an error
return path to begin with — perhaps by returning a `GError` or a
`gssize`. We can’t change the API now, though, which leads to this
slightly awkward “0 indicates an error or success” pattern.

I think that’s justified in this case because:
 - This API does not see much use.
 - Format strings tend to be literals, and almost always are
   non-zero-length, so it tends to be statically possible to determine
   that the function won’t return zero on success.
 - If callers do need to differentiate the two zero return value cases,
   they can just call `g_vsnprintf()` directly instead.

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

Helps: #3187
2023-11-27 12:20:06 +00:00
Matthias Clasen
81ec27c33b collate: Don't segfault on bad input 2023-11-26 22:41:26 +00:00
Philip Withnall
a8df4183e4 tests: Fix fileutils build on FreeBSD and macOS
The test needs to call `ftruncate64()` (not `ftruncate()`) to guarantee
it’s using the 64-bit version on Linux, but this doesn’t exist on other
platforms.

Test to see if it exists and, if not, skip the test.

Fixes commit cf5e371c67, and fixes CI
failures like https://gitlab.gnome.org/GNOME/glib/-/pipelines/602930.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-26 22:10:22 +00:00
Philip Withnall
50d432c77b gwin32: Un-hide symbols when building GIR
The win32-specific APIs in GLib are only defined when building for
Windows. Unfortunately, this means they can not show up in `GLib-2.0.gir`
if it’s build on Linux (which is what mostly happens).

Consequently, that means they’re not present in the API documentation,
which is a bit of a problem.

Make the symbols in the header available on other platforms
(particularly Linux) if building with `g-ir-scanner` (but not
otherwise). This means the win32 symbols show up in `GLib-2.0.gir` and
hence in the documentation.

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

Helps: #3037
2023-11-23 16:18:47 +00:00
Joseph Nuzman
cf5e371c67 gfileutils: Fix g_file_get_contents() silent under-read of large files
On certain platforms where file size (off_t) can be truncated when assigning to
gsize, get_contents_regfile() may use the truncated size as the size to read. Add
an explicit check to raise an error in such cases.

G_FILE_ERROR_FAILED will be raised in this case, aligning with behavior for other
cases.

This generally affects 32-bit non-Win32 platforms.
2023-11-23 12:41:41 +00:00
Philip Withnall
40e6a09d37 gstdio: Ignore POSIX stdio wrappers under g-ir-scanner
Just as they were ignored under gtk-doc, ignore them when scanning the
sources using `g-ir-scanner`, and make it look at the full function
declarations instead.

This fixes inclusion of functions like `g_creat()` in the documentation.

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

Helps: #3037
2023-11-23 12:34:39 +00:00
Philip Withnall
3c42b9c3ee gdir: Add refcounting support and a boxed type
This allows the methods for `GDir` to be introspected. While we don’t
expect languages which use the introspection bindings to use `GDir`,
full introspection support is necessary for the `GDir` documentation to
be correctly built with gi-docgen.

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

Helps: #3037
2023-11-23 12:34:39 +00:00
Philip Withnall
f0032094d2 tests: Fix use of TMPDIR in utils test
All GLib tests normally respect `TMPDIR` for writing their temporary
files to. The utils test, however, contained a hack which overwrote
`TMPDIR` so that it could test the behaviour of `g_get_tmp_dir()` for
regressions.

Unfortunately, that hack affected the whole `utils` test suite, not just
the one regression test.

Use the new `g_test_trap_subprocess_with_envp()` API to allow the
regression test to be run as a subprocess with its environment modified,
which allows us to remove the hack affecting the rest of the test suite.

Spotted in
https://gitlab.gnome.org/GNOME/glib/-/issues/3179#note_1925161.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-23 12:18:21 +00:00
Philip Withnall
6a6b36bbc7 gtestutils: Add g_test_trap_subprocess_with_envp() for testing envs
This is a variant of `g_test_trap_subprocess()` which allows the
environment for the child process to be specified. This is quite useful
when you want to test code which reads environment variables, as it’s
not safe to set those after the start of `main()`.

This will be useful within and outwith GLib for testing such code.

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

Helps: #1618
2023-11-23 12:18:21 +00:00
Philip Withnall
c7a02280f5 Merge branch 'introduce-g_log_set_debug_domains' into 'main'
gmessages: introduce g_log_set_debug_domains()

See merge request GNOME/glib!3710
2023-11-22 10:45:01 +00:00
Pablo Correa Gómez
0cae984b2d
tests: provide reason for disabling convert test under musl 2023-11-22 00:24:45 +01:00
Alexander Slobodeniuk
e862f34dd8 gmessages: introduce g_log_writer_default_set_debug_domains()
The problem is that resetting the environment of a
proccess is not safe, this is mentioned in the man
pages of the setenv, and also by the concept:
when we get a constant string returned by the getenv,
we need to be guaranteed that this string will exist
during all that time we are using it. While setting
the same env var to another value destroys this string
inside of libc.

Now looking at the should_drop_message(), we can see
that it just gets the environment on every call. Getting
the environment is safe, but however there's no safe way
to switch the logging domains selection: setenv can't be
used because of the reasons listed above.

That is why g_log_writer_default_set_debug_domains() is
needed: it's just a safe replacement for the setenv in this case.

Now should_drop_message() still reads the environment, but
does so only on the first call, after that the domains are
stored internally, and can only be changed by
g_log_writer_default_set_debug_domains().

This also means that now resetting G_MESSAGES_DEBUG env
var in runtime has no effect. But in any case this is not
what the user should do, because resetting the environment
in runtime is not correct.
2023-11-21 20:49:37 +01:00
Philip Withnall
059618956b Merge branch 'muslc-ci' into 'main'
add muslc ci

See merge request GNOME/glib!3524
2023-11-21 14:55:29 +00:00
Philip Withnall
ee94074463 Merge branch 'wip/smcv/goption-unknown' into 'main'
goption: Fix a typo

See merge request GNOME/glib!3715
2023-11-21 13:37:48 +00:00
Simon McVittie
c4a6ff6821 goption: Fix a typo
We presumably want the fallback string used when we cannot determine
the program name to contain balanced angle brackets, as it did before
commit 7098250e.

Fixes: 7098250e "gutils: avoid race setting prgname from g_option_context_parse()/g_application_run()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-21 12:55:55 +00:00
Philip Withnall
e594321ca4 docs: Move the GIOChannel SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-15 11:09:39 +00:00
Philip Withnall
7d5b6e1a85 docs: Move the GHmac SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-15 11:09:39 +00:00
Philip Withnall
09b728b2da Merge branch 'migrate-to-gi-docgen10' into 'main'
Switch to using gi-docgen for docs (batch 10)

See merge request GNOME/glib!3709
2023-11-14 15:46:30 +00:00
Philip Withnall
924e164a73 docs: Move the GRelation SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-14 14:47:53 +00:00
Philip Withnall
3981c1c704 docs: Move the GCompletion SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-14 14:47:53 +00:00
Philip Withnall
a11d3604c2 docs: Move the GCache SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-14 14:47:53 +00:00
Philip Withnall
1a979ab494 gutils: Fix an unlikely minor leak in g_build_user_data_dir()
A leak can happen if the `data_dir` is the empty string.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/3294034

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-14 11:00:21 +00:00
Pablo Correa Gómez
8901ffeffe
ci: add muslc CI 2023-11-12 15:39:14 +01:00
Thomas Haller
7098250e7a gutils: avoid race setting prgname from g_option_context_parse()/g_application_run()
g_option_context_parse()/g_application_run()/g_test_init() for
convenience also call g_set_prgname(), when the prgname is unset at this
point. This was racy.

Fix the race by using an atomic compare-and-exchange and only reset the
value, if it is unset still.
2023-11-08 16:36:14 +01:00
Thomas Haller
54e0b2d75b gutils: use atomic pointers for g_application_name
The mutex is not necessary to guard a single pointer.
2023-11-08 16:36:14 +01:00
Thomas Haller
0d61895ef1 gutils: assert against calling g_set_application_name()
g_set_application_name() guards against being reset, but it doesn't
remember whether it was set, it only checks whether g_application_name
was set to non-NULL. When allowing g_set_application_name(NULL) that leads
to odd behaviors, like:

    g_set_application_name(NULL);
    g_set_application_name("foo");

would not warn.

Disallow that and assert against a NULL application_name.

Note that application_name argument is also not marked as "(nullable)".
2023-11-08 16:36:14 +01:00
Thomas Haller
167deee94d gutils: use atomic pointers for g_prgname
The mutex is not necessary to guard a single pointer.
2023-11-08 16:36:14 +01:00
Philip Withnall
e87f8e9c5a Merge branch '3158-info-critical' into 'main'
gio-tool-info: Fix critical warning when --attributes are specified and add basic unit tests

Closes #3158

See merge request GNOME/glib!3684
2023-11-07 14:37:11 +00:00
Philip Withnall
077104e63b tests: Run processes under test with G_DEBUG=fatal-warnings
Modify all the similar Python test wrappers to set
`G_DEBUG=fatal-warnings` in the environment of the program being tested,
so we can catch unexpected warnings/criticals.

Adding this because I noticed it was missing, not because I noticed a
warning/critical was being ignored.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-07 13:51:56 +00:00
Philip Withnall
c17090275c Merge branch 'th/main-sources-dict-as-set' into 'main'
gmain: optimize "context->sources" hash table to use as set

See merge request GNOME/glib!3664
2023-11-06 15:05:43 +00:00
Philip Withnall
a766945766 Merge branch 'main' into 'main'
fix: about libproc.h and PROC_PIDLISTFD_SIZE

See merge request GNOME/glib!3687
2023-11-06 14:46:52 +00:00
CaiJingLong
7b80f73d29 fix: about libproc.h and PROC_PIDLISTFD_SIZE 2023-11-06 14:46:52 +00:00
Philip Withnall
113063e413 Merge branch 'socket-ready-fixes' into 'main'
Socket & readiness fixes

See merge request GNOME/glib!3668
2023-11-06 14:35:23 +00:00
Sergey Bugaev
a3d02ad565 gmain: Correct g_source_get_ready_time () doc
Mention that ready time being equal to the current time means the source
will fire immediately.

Related to https://gitlab.gnome.org/GNOME/glib/-/issues/3148

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-11-06 15:14:07 +03:00
Thomas Haller
b067c43b00 gmain: optimize "context->sources" hash table to use as set
Instead of tracking a "(guint,GSource*)" tuple in the "context->sources"
dictionary, only track pointers to the "source_id".

With this we use the GHashTable as Set (g_hash_table_add()), which is
optimized and avoids storing a separate value array.

It's simple enough to do, because there are literally 5 references to
"context->sources". It's easy to review those usages and reason that the
handling is correct.

While at it, in g_main_context_find_source_by_id() move the check for
SOURCE_DESTROYED() inside the lock. It's not obvious that doing this
without a lock was correct in every case. But doing the check with
a lock should be fast enough to not worry about whether it's absolutely
necessary.
2023-11-06 08:48:12 +01:00
Thomas Haller
501bdb51e4 glib: add internal G_CONTAINER_OF() macro
"container_of()" is a popular macro that works together with
G_STRUCT_OFFSET()/offsetof().

For internal use only.
2023-11-06 08:48:12 +01:00
Thomas Haller
3c09257ea1 glib: add internal g_uint_hash()/g_uint_equal()
We have g_int_hash()/g_int_equal(), which in practice might also work
with with pointers to unsigned integers. However, according to strict
interpretation of C, I think it is not valid to conflate the two.

Even if it were valid in all cases that we want to support, we should
still have separate g_uint_{hash,equal} functions (e.g. by just #define
them to their underlying g_int_{hash,equal} implementations).

Add instead internal hash/equal functions for guint.
2023-11-06 08:48:12 +01:00
Philip Withnall
32e8a73efb tests: Refactor thread-pool-slow to separate test functions
Previously thread-pool-slow ran a single test which encoded a state
machine and polling timer to run 8 different sub-tests and check for
their exit conditions.

This was a bit ugly, and since the timer ran at 1s granularity, several
of the tests completed quite fast and then hang around for most of 1s
before finishing and moving to the next test.

Split the test functions up into separate GTest tests, and split the
state machine up between the test functions. All of the `GMainLoop`
handling is actually only needed for the `test_threadpool_idle_time()`
test.

This reduces the overall test runtime from 36s to 19s on my machine,
with 17s of that being spent in `test_threadpool_idle_time()`.

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

Helps: #2810
2023-11-03 12:10:49 +00:00
Philip Withnall
1195a7a638 tests: Move some global variables into local scope in thread-pool-slow
This makes things a bit more maintainable, as there’s less global state
to worry about.

It introduces no functional changes.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-03 11:40:44 +00:00
Philip Withnall
f0dbf6fe7c tests: Remove dead code from thread-pool-slow
This variable was never modified.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-03 11:38:41 +00:00
Philip Withnall
0b45f6208b tests: Fix a race in thread-pool-slow
The race was already acknowledged in the code (via `last_failed`): the
thread pool starts dequeuing jobs as soon as it’s created, so it’s
dequeuing the sorted thread IDs while they’re still being enqueued and
sorted. This can lead to them being dequeued out of the expected order
if new thread IDs are enqueued out of order, which is possible because
they’re randomly generated.

The test tried to handle this by allowing one out-of-order dequeue, but
it looks like the race can race hard enough that multiple out-of-order
dequeues are possible.

Fix that by only starting to dequeue the jobs from the thread pool once
they’ve all been enqueued and put in a total order.

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

Fixes: #2810
2023-11-03 11:14:51 +00:00
Philip Withnall
0fe15f9b9b docs: Move the GChecksum SECTION
Move it to the struct docs.

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

Helps: #3037
2023-11-02 16:30:23 +00:00
Alexander Slobodeniuk
ae8018d360 gmessages: fix dropping irrelevant log domains
If the string of one log domain is contained in
another, it was printing both.

For example, if G_MESSAGES_DEBUG is "Gtkspecial",
it would also keep the logs of the "Gtk" domain
2023-11-01 22:24:45 +00:00
Philip Withnall
3b4846611d glib: Disable dynamic asan loading on macOS
The weak symbol resolution doesn’t seem to work (see
https://gitlab.gnome.org/GNOME/glib/-/jobs/3265405):
```
Undefined symbols for architecture x86_64:
  "___lsan_enable", referenced from:
      _g_leak_sanitizer_is_supported in gutils.c.o
  "___lsan_ignore_object", referenced from:
      _g_ignore_leak in gquark.c.o
      _g_ignore_leak in gthreadpool.c.o
      _g_ignore_leak in gutils.c.o
      _g_leak_sanitizer_is_supported in gutils.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

See !3672

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-01 14:34:37 +00:00
Seppi Wilhelmi
fc3d3a5499 Make GQuark register intentional leaks 2023-10-31 16:53:40 +01:00
Marco Trevisan (Treviño)
fb58d55187 glib-private: Check for LSAN support at runtime when controlling it
GLib ignores various leaks that we don't consider as such (like the
default gio modules) via the LSAN public interface, however those cases
are always ignored when using a non-ASAN compiled glib is used by an
ASAN-compiled binary.

This makes all the GLib-related programs to fail because of false
positive leaks.

To avoid this, use the gcc extension for weak linking so that we can
control ASAN and LSAN only if the symbols they provide are actually
available at runtime.
2023-10-27 18:31:53 +02:00
Marco Trevisan (Treviño)
d354b2f55e gmacros: Add fallback definition for weak attribute 2023-10-27 17:19:08 +02:00
Michael Catanzaro
eadbdb439e Merge branch 'meson-version-bump' into 'main'
build: Bump Meson dependency to 1.2.0

See merge request GNOME/glib!3666
2023-10-25 13:23:53 +00:00
Alex Richardson
d0e03f0930 GType: introduce GTYPE_TO_POINTER/GPOINTER_TO_TYPE
On CHERI-enabled systems we use uintptr_t as the underlying storage for
GType and therefore casting to gsize strips the upper bits from a pointer.
Fix this by casting via uintptr_t instead and introduce a new set of
macros to convert between GType and pointers.
2023-10-25 12:01:02 +01:00
Philip Withnall
7fd9045065 build: Drop pkgconfig.generate variables for builtin directories
Meson has added these automatically since 0.62. This fixes a Meson
warning.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-10-25 11:21:24 +01:00
Philip Withnall
70c66766f7 Merge branch 'atomic-uintptr' into 'main'
gatomic: Use g(u)intptr where appropriate

See merge request GNOME/glib!3143
2023-10-24 10:49:30 +00:00
Emmanuele Bassi
fe32c3f5c5 Generate introspection data
Currently, the introspection data for GLib and its sub-libraries is
generated by gobject-introspection, to avoid the cyclic dependency
between the two projects.

Since gobject-introspection is generally available on installed systems,
we can check for its presence, and generate the introspection data
directly from GLib.

This does introduce a cyclic dependency, which is why it's possible to
build GLib without introspection, then build gobject-introspection, and
finally rebuild GLib.

By having introspection data available during the GLib build, we can do
things like generating documentation; validating newly added API; and
close the loop between adding new API and it becoming available to non-C
consumers of the C ABI (i.e. language bindings).
2023-10-23 11:26:53 +01:00
Emmanuele Bassi
5e7c512609 docs: Fix various invalid links 2023-10-23 10:25:31 +01:00
Emmanuele Bassi
c86f469c1e Ignore autocleanups when generating introspection data 2023-10-23 10:25:30 +01:00
Emmanuele Bassi
c5eb130175 Fix broken annotation in GIOChannel
Missing separator between annotation and description.
2023-10-23 10:25:30 +01:00
Michael Catanzaro
ceca2dc5bc Merge branch '3144-file-set-contents-truncation' into 'main'
gfileutils: Add a missing ftruncate() call when writing files

Closes #3144

See merge request GNOME/glib!3650
2023-10-22 22:41:56 +00:00
Michael Catanzaro
7a9f8eec35 Merge branch 'alt-digits-locale-change' into 'main'
gdatetime: Fix incorrect alt-digits being used after changing locale

See merge request GNOME/glib!3655
2023-10-22 22:32:34 +00:00
Philip Withnall
afd8dde13f gdatetime: Fix incorrect alt-digits being used after changing locale
The alt-digits are loaded from `nl_langinfo()` in a `GOnce` section,
which means `nl_langinfo()` is not re-queried after the process changes
locale (if that happens).

So, change the `GOnce` to a mutex and store the locale of the alt-digits
alongside them. This will introduce contention when calling
`format_number()` is called, but how often are multiple threads trying
to format dates at the same time?

If this does get highlighted as a performance problem, the other
approach I considered was a `GPrivate` struct containing all the
locale-specific cached data. That comes at the cost of using a
`GPrivate` slot (although that’s only particularly expensive on Windows,
and the locale code is quite different for Windows, so perhaps that
could be avoided entirely). It does mean that all locale printing could
be lock-free and still safely update cached data on a locale change.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-22 22:10:07 +01:00
Philip Withnall
3f705ffa12 gfileutils: Add a missing ftruncate() call when writing files
When calling `g_file_set_contents_full()` without
`G_FILE_SET_CONTENTS_CONSISTENT`, the file is written by opening it,
`write()`ing to it, then closing it.

This is fine as long as the file is not longer than the new content you
want to set its contents to. If it is, the last bit of the old content
remains, because `g_file_set_contents_full()` was missing an
`ftruncate()` call.

Fix that, and change the tests to catch truncation failures in future.

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

Fixes: #3144
2023-10-22 21:37:28 +01:00
Marco Trevisan
ca57acd71b Merge branch '3112-unicode-15.1' into 'main'
gunicode: Update to Unicode 15.1.0

Closes #3112

See merge request GNOME/glib!3651
2023-10-19 17:02:37 +00:00
Philip Withnall
b1ae8fb85f gdatetime: Fix minor leaks from strup/strdown calls
These were accidentally introduced in commit 0b114b2687.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-18 15:54:33 +01:00
Philip Withnall
17145fab35 gunicode: Update to Unicode 15.1.0
All changes mechanically generated with:
```
./tools/update-unicode-data.sh ~/Downloads/UCD 15.1.0
```

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

Fixes: #3112
2023-10-17 22:59:27 +01:00
Philip Withnall
80aea8e0a6 gen-unicode-tables: Fix indentation at the start of the first row
It was annoying Marco.

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

Helps: #3112
2023-10-17 22:59:27 +01:00
Philip Withnall
cc350774bf gen-unicode-tables: Strip whitespace off parsed fields
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-17 22:45:55 +01:00
Philip Withnall
9770d7ba31 gunicode: Fix a minor typo in a documentation comment
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-10-17 22:45:55 +01:00
Philip Withnall
444a313b1f gunicode: Add new line-break types from Unicode 15.1.0
See https://unicode.org/reports/tr14/

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

Helps: #3112
2023-10-17 22:45:55 +01:00
Philip Withnall
fa165204ae Merge branch 'fix-warnings-clang-windows' into 'main'
Fix warnings with Clang on Windows and enable --Werror in CI

See merge request GNOME/glib!3635
2023-10-16 21:29:09 +00:00
Luca Bacci
4aa051cafb valgrind.h: Fix macro definition for Windows x64
The Windows x64 ABI follows the LLP64 model, so unsigned long int is 32 bits

Fixes the following warnings when compiling for Windows x64:

  ../glib/gobject/gatomicarray.c:85:3: warning: cast to smaller integer type 'unsigned long' from 'gpointer' (aka 'void *') [-Wvoid-pointer-to-int-cast]
    VALGRIND_MALLOCLIKE_BLOCK (mem, real_size - sizeof (GAtomicArrayMetadata),
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../glib/glib/valgrind.h:6479:5: note: expanded from macro 'VALGRIND_MALLOCLIKE_BLOCK'
      VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK,       \
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../glib/glib/valgrind.h:203:15: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUEST_STMT'
    do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0,                        \
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../glib/glib/valgrind.h:417:20: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUEST_EXPR'
      _zzq_args[1] = (unsigned long int)(_zzq_arg1);                \
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

See https://bugs.kde.org/show_bug.cgi?id=427146
2023-10-16 15:02:03 +02:00
Philip Withnall
481839c190 Merge branch 'win32-unicode-api' into 'main'
Windows: Compile with the UNICODE / _UNICODE macros

See merge request GNOME/glib!3623
2023-10-16 08:58:41 +00:00
Philip Withnall
b8e805b8c6 Merge branch 'update-bit-symbol' into 'main'
gutils: Use international symbol for bits

See merge request GNOME/glib!3552
2023-10-16 08:25:03 +00:00
getsnoopy
5422d2fdb8 gutils: Use international symbol for bits 2023-10-16 08:25:03 +00:00
Guido Günther
bc4ba05d34 gstrvbuilder: Add g_strv_builder_take
g_strv_builder_take() allows to transfer ownership of the passed in
string.

This can be useful to avoid additional allocations when using functions
that transfer ownership to the caller like g_strdup_printf().

The testcase uses g_strv_builder_take and g_strv_builder_add to demo
that calls can be mixed.
2023-10-15 15:45:58 +02:00
Luca Bacci
dfeb671c36 tests/win32: Initialize DWORD with the right constant
We were initializing a DWORD (unsigned 32 bit) with a constant
of bigger rank (G_MAXSIZE) on 64 bit systems.

Fixes the following warnings on CLang when compiling for x64:

  ../glib/glib/tests/win32.c:47:14: warning: implicit conversion from 'unsigned long long' to 'DWORD' (aka 'unsigned long') changes value from 18446744073709551615 to 4294967295 [-Wconstant-conversion]
    DWORD bp = G_MAXSIZE;
          ~~   ^~~~~~~~~
  glib/glibconfig.h:88:19: note: expanded from macro 'G_MAXSIZE'
  #define G_MAXSIZE       G_MAXUINT64
                          ^~~~~~~~~~~
  ../glib/glib/gtypes.h:107:21: note: expanded from macro 'G_MAXUINT64'
  #define G_MAXUINT64     G_GUINT64_CONSTANT(0xffffffffffffffff)
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  glib/glibconfig.h:69:52: note: expanded from macro 'G_GUINT64_CONSTANT'
  #define G_GUINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##ULL))
                                                     ^~~~~~~~
  <scratch space>:96:1: note: expanded from here
  0xffffffffffffffffULL
  ^~~~~~~~~~~~~~~~~~~~~
2023-10-12 11:45:33 +02:00
Luca Bacci
8264b13737 tests/cxx: Do not assume that NULL is a pointer type starting with C++11
Many toolchain did not change the definition of NULL to avoid introducing
breaking changes in existing codebases. For example, on Windows NULL is
0 (int) regardless of the C++ standard in use.

Fixes the following warnings on CLang when compiling for Windows:

  ../glib/glib/tests/cxx.cpp:539:34: warning: missing sentinel in function call [-Wsentinel]
    g_test_init (&argc, &argv, NULL);
                                   ^
                                   , nullptr
  ../glib/glib/gtestutils.h:298:9: note: function has been explicitly marked sentinel here
  void    g_test_init                     (int            *argc,
          ^

  ../glib/gio/tests/cxx.cpp:62:34: warning: missing sentinel in function call [-Wsentinel]
    g_test_init (&argc, &argv, NULL);
                                   ^
                                   , nullptr
  ../glib/glib/gtestutils.h:298:9: note: function has been explicitly marked sentinel here
  void    g_test_init                     (int            *argc,
          ^
2023-10-12 11:45:03 +02:00
Luca Bacci
107311afce glib/gtimezone.c: Declare Unix-only functions under G_OS_UNIX
Fixes the following warnings on CLang when compiling for Windows:

  ../glib/glib/gtimezone.c:95:22: warning: unused function 'gint64_from_be' [-Wunused-function]
  static inline gint64 gint64_from_be (const gint64_be be) {
                       ^
  ../glib/glib/gtimezone.c:99:22: warning: unused function 'gint32_from_be' [-Wunused-function]
  static inline gint32 gint32_from_be (const gint32_be be) {
                       ^
  ../glib/glib/gtimezone.c:103:23: warning: unused function 'guint32_from_be' [-Wunused-function]
  static inline guint32 guint32_from_be (const guint32_be be) {
                        ^
2023-10-12 11:44:59 +02:00
Luca Bacci
5400f4e128 glib/gmessages.c: Remove unused function
Fixes the follwing warning on CLang:

  ../glib/glib/gmessages.c:433:1: warning: unused function 'dowrite' [-Wunused-function]
  dowrite (int          fd,
  ^
2023-10-12 11:44:56 +02:00
Luca Bacci
f075db637a glib/giowin32.c: Add G_GNUC_FALLTHROUGH annotation
Fixes the following warning on CLang:

  ../glib/glib/giowin32.c:1665:7: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
        default:
        ^
  ../glib/glib/giowin32.c:1665:7: note: insert '__attribute__((fallthrough));' to silence this warning
        default:
        ^
        __attribute__((fallthrough));
  ../glib/glib/giowin32.c:1665:7: note: insert 'break;' to avoid fall-through
        default:
        ^
        break;
2023-10-12 11:44:48 +02:00
Luca Bacci
337912072a Windows: Compile with the UNICODE / _UNICODE macros
It's the recommended way to build C/C++ projects on Windows, see
https://learn.microsoft.com/en-us/windows/win32/intl/conventions-for-function-prototypes
2023-10-12 11:32:03 +02:00
Matthias Clasen
f679a784d2 docs: Drop the GQuark SECTION
Move the content to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
5a2a0aeaf9 docs: Move the GStringChunk SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
57219c14a0 docs: Move the GTimer SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
a47bdb2638 docs: Move GRegex SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
45f6f43fc6 docs: Mark all GWakeup docs as private
This is not public API.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
ccfedf08cb docs: Move the GPatternSpec SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
f2b1e4d936 docs: Move the GKeyFile SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
f27af99233 docs: Move the unicode SECTION
Move the content to the new unicode.md file.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
6052639a5c docs: Update Unicode version history
Unicode 14 and 15 were missing from this list.
2023-10-11 17:38:31 +01:00
Matthias Clasen
55a844a465 docs: Move the GDate SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
1dae4fc618 docs: Move the GPathBuf SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
be9a463a10 docs: Move the GStrvBuilder SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
c50f94e41e docs: Move the GScanner SECTION
Not much here to begin with.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
5a415ee93f docs: Move the GTimeZone SECTION
Move the contents to the struct docs.

Helps: #3037
2023-10-11 17:38:31 +01:00
Matthias Clasen
7b4d00e0a4 docs: Move GDateTime SECTION
Move the contents to the struct comment.

Helps: #3037
2023-10-11 17:38:30 +01:00
Matthias Clasen
7fd50be9d0 docs: Move bookmarkfile SECTION
Move the content to the struct docs.

Helps: #3037
2023-10-11 17:38:30 +01:00