Commit Graph

27461 Commits

Author SHA1 Message Date
Philip Withnall
f5b2aeaf39 Merge branch '2876-api-public-or-internal' into 'main'
gutils: Make g_find_program_for_path() a proper private API

Closes #2876

See merge request GNOME/glib!3267
2023-02-13 17:31:28 +00:00
Philip Withnall
a359e56f58 gutils: Remove public API decorator from g_set_user_dirs()
It’s a private API, and is not meant to be exposed in the public API.
Since it’s only used internally within libglib, we don’t have to expose
it in the public symbol table, so drop the decorator.

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

Helps: #2876
2023-02-13 16:14:10 +00:00
Philip Withnall
438bd5cfa1 gutils: Make g_find_program_for_path() a proper private API
It’s not meant to be exposed publicly yet (we’re not ready to stabilise
it), but it was incorrectly decorated with `GLIB_AVAILABLE_IN_2_76`.

We can’t remove the decorator and use it that way, as it’s called in
libgio, so we have to expose it using `GLIB_PRIVATE_CALL()`.

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

Fixes: #2876
2023-02-13 16:12:07 +00:00
Emmanuele Bassi
585c7d2db6 Merge branch 'wip/smcv/symlink-detection-doc' into 'main'
fileutils: Make some sample code detect symlinks as intended

See merge request GNOME/glib!3265
2023-02-10 20:52:08 +00:00
Alex Richardson
9f8edb1e3f GVariant: ensure GVariantIter alignment for CHERI systems
For CHERI-enabled architectures such as Arm Morello we have to align the
GVariantIter to pointer alignment (16 bytes for Morello) but defining the
opaque struct as 16 gsize elements only aligns to 8 bytes.
This does not change the layout for existing architecutre since there
gsize is the same as guintptr.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-02-10 18:22:20 +00:00
Alex Richardson
147777e342 GHash: Don't use SMALL_ENTRY_SIZE for CHERI
The code for SMALL_ENTRY_SIZE assumes pointers are no larger than 8 bytes,
so instead of trying to make it work disable the optimization for now.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
Co-authored-by: Graeme Jenkinson <graeme@capabilitieslimited.co.uk>
2023-02-10 18:22:20 +00:00
Alex Richardson
5d8ecac1ec Make GVariantBuilder and GVariantDict layout compatible with CHERI
Use guinptr instead if gsize. While this increases the structure size
for Morello, it is still only 256 bytes which should not matter for a
type where we expect few instances to exist at any given time.
This does not increase the size for existing architectures since gsize
is the same as guintptr for all of them.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-02-10 18:22:20 +00:00
Alex Richardson
2aed76fc94 Fix GHashTableIter layout for CHERI targets
Last field needs to be pointer-size to match GHashTableIter. This happened
to work for most architecture due to alignment padding/pointer size, but
for CHERI targets with 128-bit pointers RealIter ends up being smaller
than GHashTableIter.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-02-10 18:22:20 +00:00
Simon McVittie
702e606f73 Merge branch 'wip/smcv/pathbuf-windows' into 'main'
pathbuf: Treat forward slashes and backslashes as equivalent on Windows

Closes #2914

See merge request GNOME/glib!3264
2023-02-10 15:41:31 +00:00
Philip Withnall
9ab080c6ce Merge branch 'wip/smcv/gi-warnings' into 'main'
Avoid some warnings from GObject-Introspection

See merge request GNOME/glib!3266
2023-02-10 13:49:22 +00:00
Simon McVittie
6631e6dc1f Merge branch 'wip/smcv/gsize-is-guintptr-for-now' into 'main'
Add a (temporary) assertion that sizeof(gsize) == sizeof(guintptr)

See merge request GNOME/glib!3262
2023-02-10 13:17:36 +00:00
Simon McVittie
ee223e8ec8 gtimezone: Avoid a nested preprocessor conditional to be nice to g-i
GObject-Introspection seems to become confused by the nested conditional
followed by an `#elif` clause for the outer conditional, and issues
this warning:

.../gtimezone.c:830: mismatched #elif  defined (G_OS_WIN32)

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 13:16:01 +00:00
Simon McVittie
30352032a6 gstrfuncs: Use separate preprocessor conditionals for g-i and gtk-doc
GObject-Introspection and gtk-doc both parse C headers using regular
expressions, so they can easily be confused by non-trivial conditions.
GObject-Introspection warns about this:

    .../gstrfuncs.h:151: the __GI_SCANNER__ constant should only be used with simple #ifdef or #endif: #if  !defined (__GTK_DOC_IGNORE__) && !defined (__GI_SCANNER__)

In this case it's very easy to convert the compound expression into
nesting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 13:14:42 +00:00
Simon McVittie
f6e13753aa fileutils: Make some sample code detect symlinks as intended
The sample code here wasn't a race-free version of the race-susceptible
anti-pattern, because it would have dereferenced a symlink automatically.

Fixes: 293b4923 "Clarify g_file_test() docs about TOCTOU bugs"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 13:06:04 +00:00
Simon McVittie
def7c0ac10 pathbuf: Treat forward slashes and backslashes as equivalent on Windows
The canonical directory separator is a backslash, but some Windows APIs
allow either, interchangeably. Do the same here.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2914
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 11:13:36 +00:00
Alex Richardson
14ae87f379 Add a (temporary) assertion that sizeof(gsize) == sizeof(guintptr)
Glib does not yet have a well defined ABI/API for architectures
where gsize != guintptr (e.g. CHERI). To enable working on bringup
for new architectures this assertion can be disabled with
`-DG_ENABLE_EXPERIMENTAL_ABI_COMPILATION`.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2842

[smcv: Apply review comments from pwithnall]

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-10 10:54:36 +00:00
Philip Withnall
d5bf03cbcb Merge branch 'wip/smcv/redundant-type-assertions' into 'main'
Revert "glib-init: Add more static assertions for gintptr, guintptr"

See merge request GNOME/glib!3263
2023-02-09 23:03:30 +00:00
Simon McVittie
73c91ef799 Revert "glib-init: Add more static assertions for gintptr, guintptr"
On closer inspection, these are redundant with stricter assertions that I
added in commit bd1e2a98 "glib-init: Statically assert more facts about
standard types", which assert that sizeof (gintptr) == sizeof (void *).

As far as I can tell, a sufficiently pedantic interpretation of Standard
C doesn't actually require (u)intptr_t to be the same size as a pointer:
it only requires that pointers can be losslessly stored in a (u)intptr_t,
which a sufficiently pathological ABI could implement by having (for
example) 32-bit pointers and a 64-bit uintptr_t just to troll us. However,
I'm fairly confident that no practically useful ABI would do this,
and certainly nobody has complained about this assertion since 2020.

Similarly, Standard C might permit an ABI where 64-bit pointers have the
first 32 bits always-zero and therefore storing the remaining bits in a
32-bit uintptr_t is lossless, but again, that would be pathological.

This reverts commit da3fc59544.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-09 19:08:08 +00:00
Emmanuele Bassi
816b35df67 Merge branch 'ebassi/pathbuf' into 'main'
Add GPathBuf

See merge request GNOME/glib!3216
2023-02-09 13:55:26 +00:00
Emmanuele Bassi
fcdbd7f9bd tests: Add GPathBuf to the g_auto suite 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
7e62d01053 tests: Add PathBuf.new_from_path() coverage 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
d0ee88078b doc: Clarify g_path_buf_to_path()
The returned path is built on demand.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
a05fda9990 Move GPathBuf tests into their own file
Keep the fileutils tests related to the gfileutils.h API.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
280649fb82 docs: Clarify the path construction functions
Use the same wording for functions that belong in the same family, and
link to the newly introduced GPathBuf API.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
314d62f302 doc: Make file utils docblocks render nicely with gi-docgen
Do not use 4-spaces indentation for return and argument descriptions, to
avoid getting rendered as preformatted blocks.

Annotate code examples with their language, for syntax highlighting.

Isolate the first paragraph to give a short description.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
293b492334 Clarify g_file_test() docs about TOCTOU bugs
Do not show just what not to do: show what to do instead, otherwise
people won't know how to fix their code.

Make sure to link to an explanation of the TOCTOU class of bugs;
Wikipedia is as good a place as any.
2023-02-09 13:36:51 +00:00
Emmanuele Bassi
b5a3297dca docs: Add GPathBuf to the API reference 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
2015723a4f Add tests for GPathBuf 2023-02-09 13:36:51 +00:00
Emmanuele Bassi
f60f432b6c Add GPathBuf
GPathBuf is a path buffer type that can be used to build paths
programmatically, using it as a stack.
2023-02-09 13:36:51 +00:00
Philip Withnall
728ad64b44 glocalfileinfo: Ensure boolean file attributes are set
Don’t just set them when they’re true and rely on their non-presence
being evaluated to `FALSE`. That means that they erroneously don’t get
returned in `g_file_info_list_attributes()`.

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

Helps: #2907
2023-02-08 11:58:15 +00:00
Philip Withnall
7082f03dbf gio-tool-info: Add missing attribute check
`g_file_info_get_is_hidden()` should not be called without checking the
attribute is set first, just as with the calls higher up in this code.

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

Helps: #2907
2023-02-08 11:58:15 +00:00
Philip Withnall
ed8e86a7d4 gfileinfo: Add critical warnings for helper getters
As documented in a previous commit, these functions should not be called
without the right attributes being present in the `GFileInfo`. Add
critical warnings to make this more obvious.

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

Fixes: #2907
2023-02-08 11:58:15 +00:00
Philip Withnall
8cee721df8 gfileinfo: Remove erroneous GFileType casts from returns
Looks like copy/paste errors.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-08 10:00:43 +00:00
Philip Withnall
2f862993cc gfileinfo: Fix some minor documentation typos
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-08 09:57:51 +00:00
Philip Withnall
937c6f15cd gfileinfo: Document required attributes for helper getters
It doesn’t make sense to (for example) call `g_file_info_get_name()` if
the `GFileInfo` doesn’t contain `G_FILE_ATTRIBUTE_STANDARD_NAME`, given
that building the `GFileInfo` is typically a static process and entirely
under the control of the programmer.

By being this restrictive, we avoid having to return ‘unknown’ values
for some of these standard APIs, particularly the numeric ones such as
`g_file_info_get_size()`. If APIs like that were to work correctly in
the face of a `GFileInfo` without `G_FILE_ATTRIBUTE_STANDARD_SIZE`
specified, they’d have to be able to return a value to indicate the
attribute is missing. Returning `0` or `G_MAXSIZE` to indicate that
would be ambiguous.

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

Fixes: #2907
2023-02-08 09:54:54 +00:00
Marco Trevisan
5821425e11 Merge branch 'underspecified-dep' into 'main'
fix underspecified dependencies on generated headers

See merge request GNOME/glib!3260
2023-02-07 14:35:52 +00:00
Marco Trevisan
9201a20276 Merge branch 'th/no-mutex-in-g-print' into 'main'
gmessages: use g_atomic_pointer to access handlers for g_print()/g_printerr()

See merge request GNOME/glib!3259
2023-02-07 14:32:15 +00:00
Thomas Haller
4d7f66f214 gmessages: use g_atomic_pointer to access handlers for g_print()/g_printerr()
It seems unnecessary to use the mutex to get/set a single pointer.
2023-02-07 13:16:07 +01:00
Eli Schwartz
740440774a
fix underspecified dependencies on generated headers
Since gmodule-visibility.h is now a custom target and produced at
buildtime, it might not always exist in time for use in other source
files. This was the case for gio-inotify.

Add it as an additional source file to ensure in-time generation.
2023-02-06 23:00:04 -05:00
Philip Withnall
4177164fd2 Merge branch 'wip/pwithnall/revert-freebsd-ci' into 'main'
Revert "ci: Temporarily only run the FreeBSD 13 CI on a schedule"

See merge request GNOME/glib!3258
2023-02-06 16:52:11 +00:00
Philip Withnall
e6132f2322 Revert "ci: Temporarily only run the FreeBSD 13 CI on a schedule"
This reverts commit 163ebdc6c2.

The FreeBSD CI runner is back again.

See https://gitlab.gnome.org/Infrastructure/GitLab/-/issues/601#note_1658477
2023-02-06 14:58:47 +00:00
Philip Withnall
6ba1627fe6 Merge branch 'g-atomic-array-alignment' into 'main'
GAtomicArray: Ensure metadata does not misalign the payload

See merge request GNOME/glib!3242
2023-02-06 14:08:06 +00:00
Philip Withnall
361745149f Merge branch 'msort-cheri' into 'main'
Allow using msort_r CHERI-enabled architectures

See merge request GNOME/glib!3243
2023-02-06 14:04:18 +00:00
Philip Withnall
bd8b756853 Merge branch 'gtype-use-sized-free' into 'main'
Revert "gtype: Use the system allocator on UNIX" and use g_free_sized instead

See merge request GNOME/glib!3251
2023-02-06 14:00:38 +00:00
Marco Trevisan
5c34cf3dbb Merge branch 'ebassi/no-preallocs' into 'main'
Remove n_preallocs field from InstanceData

See merge request GNOME/glib!3256
2023-02-06 13:33:16 +00:00
Emmanuele Bassi
8f92f742b9 Remove n_preallocs field from InstanceData
The GTypeInfo.n_preallocs field has been ignored since GLib 2.10, but it
hasn't been removed from the internal instance data representation.
2023-02-04 16:55:30 +01:00
Michael Catanzaro
35170735de Merge branch 'force-non-null-gslice-free' into 'main'
gslice: Do not try to memset-0 NULL a pointer

Closes #2908

See merge request GNOME/glib!3253
2023-02-03 23:19:43 +00:00
Marco Trevisan (Treviño)
893b86b939 gslice: Mark memory arguments and return values as nullable when it's the case
GSlice can handle NULL arguments or return NULL values, but we did not
properly mark them all the times.
2023-02-03 16:28:51 +01:00
Marco Trevisan (Treviño)
6af6f3eb9b gslice: Do not try to memset-0 NULL a pointer
According to the docs, g_slice_free1() is supposed to do nothing if
@mem_block is NULL, but we still try to zero it in case we're using
g_mem_gc_friendly.

So avoid this case.

Closes: #2908
2023-02-03 16:28:37 +01:00
Marco Trevisan (Treviño)
69e9ba80e2 gtype: Use g_malloc0 and g_free_sized to allocate and free memory
We've a sized free now, so we can just use it!
2023-02-03 11:38:00 +01:00