Commit Graph

2867 Commits

Author SHA1 Message Date
Patrick Griffis
de2ff26454 Merge branch '116-utf8-docs' into 'main'
docs: Document high-level UTF-8 requirements for GLib

Closes #116

See merge request GNOME/glib!3414
2023-05-02 19:20:30 +00:00
Philip Withnall
377e8a2d9e docs: Update various broken/redirected links
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-05-02 14:26:52 +01:00
Peter Eisenmann
3abf23b2a7 add g_timeout_add_seconds_once
Add a new call combing behaviors of g_timeout_add_seconds and
g_timeout_add_once.
2023-05-02 13:42:54 +02:00
Philip Withnall
0e941418d1 docs: Document high-level UTF-8 requirements for GLib
I’ve finally found the right place in the docs to put this stuff.

This doesn’t auto-link this section from every string in the GLib
documentation, but I think that at this point (with gtk-doc in
maintenance mode, and gi-docgen not fully applied to GLib) I don’t think
we can do any better. The perfect is the enemy of the good, and having
this stuff documented somewhere means that someone can link to it from
multiple places in future *somehow*.

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

Fixes: #116
2023-05-02 10:41:50 +01:00
Patrick Griffis
f009d8e368 Merge branch '2289-setuid-docs' into 'main'
docs: Document that GIO should not be used in privileged processes

Closes #2289

See merge request GNOME/glib!3413
2023-04-29 03:28:10 +00:00
Philip Withnall
f42e04d247 docs: Document that GIO should not be used in privileged processes
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2289
2023-04-28 11:11:03 +01:00
Philip Withnall
e43b2452b9 docs: Add high-level documentation about malloc failure
While I’m here.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-28 11:01:25 +01:00
Philip Withnall
3b9fc71644 docs: Mention that calls after fork() must be async-signal-safe
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2958
2023-04-28 11:00:33 +01:00
Philip Withnall
9b8369852b Merge branch 'html-doc-flag' into 'main'
meson: wrap html documentation generation with gtk_doc option

See merge request GNOME/glib!3399
2023-04-28 01:09:04 +00:00
James Knight
0fa17ec3c7 meson: wrap html documentation generation with gtk_doc option
By default, if a host environment has the `rst2html5` application
available, builds will automatically perform some HTML documentation
generation from the documentation's glib reference content (e.g.
creating `gvariant-specification-1.0.html`). The creation of this
documentation is not required for all use cases.

This commit tweaks the building of the HTML-based GLIB specification
document to be guarded by `gtk_doc`.

Signed-off-by: James Knight <james.d.knight@live.com>
2023-04-27 20:23:30 -04:00
Philip Withnall
7922d3200c Merge branch 'resolver-thread-pool' into 'main'
gthreadedresolver: Switch to using a separate thread pool and support timeouts

See merge request GNOME/glib!3397
2023-04-27 12:46:53 +00:00
Philip Withnall
bf92bae481 gresolver: Add GResolver:timeout property
Without a timeout, some lookup requests can go on forever, typically due
to bugs in underlying systems.

This can have particularly significant effects on the Happy Eyeballs
algorithm in `GSocketClient`, which relies on multiple name lookups as
its first step.

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

Helps: #2866
2023-04-27 12:23:25 +01:00
Emmanuele Bassi
e2e93056f2 Add init macros for refcounting types
We need a way to initialise refcounted types placed in static storage,
or on the stack. Using proper macros avoids knowing the magic constant
used for grefcount and gatomicrefcount.
2023-04-24 12:48:32 +01:00
Philip Withnall
da35056247 Merge branch 'registry-settings-root-key' into 'main'
gregistrysettingsbackend: Allow a different root key path

See merge request GNOME/glib!3306
2023-04-14 17:00:01 +00:00
Dario Saccavino
fee0a7679a gregistrysettingsbackend: Allow a different root key path 2023-04-14 17:00:01 +00:00
Xavier Claessens
8d27474631 doc: Workaround missing API index 2023-04-14 17:08:35 +01:00
Philip Withnall
e993e27782 docs: Add 2.78 release series documentation pages to the build
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-14 16:09:34 +01:00
Philip Withnall
783f1b8640 gtype: Improve documentation for G_TYPE_IS_CLASSED and interfaces
The documentation previously implicitly said in a few places that
interfaces are classed, but reading through the implementation of
`GType`, I don’t think they are. If they were, the registration of the
fundamental `G_TYPE_INTERFACE` in `gobject_init()` would specify
`G_TYPE_FLAG_CLASSED`. It only specifies `G_TYPE_FLAG_DERIVABLE`.

I think this makes sense, because you can’t subclass an interface.
Subclassing is a key property of being classed.

Tweak the `GType` tutorial to remove that implicit statement, and expand
the documentation for `G_TYPE_IS_CLASSED`.

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

Fixes: #252
2023-04-13 15:37:00 +01:00
Sam Thursfield
2d216d4d8c Link goption documentation to GOptionContext type
This makes the goption overview visible in the gi-docgen docs as part of
the GOptionContext type. Previously it was not visible anywhere.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2953
2023-03-23 14:01:45 +00:00
Maciej S. Szmigiero
14b5207bfa Add g_unix_open_pipe_internal () for pipes with the close-on-exec flag
Based on the existing g_unix_open_pipe () but for internal use where
returning a raw errno is needed, not a GError.
2023-02-21 12:42:55 +00:00
Emmanuele Bassi
b5a3297dca docs: Add GPathBuf to the API reference 2023-02-09 13:36:51 +00:00
Philip Withnall
329843f682 gmem: Add g_free_sized() and g_aligned_free_sized()
These wrap `free_sized()` and `free_aligned_sized()`, which are present
in C23[1]. This means that user code can start to use them without checking
for C23 support everywhere first.

It also means we can use them internally in GSlice to get a bit of
performance for the code which still uses it.

See https://en.cppreference.com/w/c/memory/free_aligned_sized and
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2699.htm.

[1]: Specifically, section 7.24.3.4 of the latest C23 draft at
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3088.pdf.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-02 12:30:59 +00:00
Natanael Copa
45b5a6c1e5 gslice: Remove slice allocator and use malloc() instead
Keep the API for ABI compatibility.

See
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2935#note_1650099
for a summary of the reasoning for this change:
 - The performance of system-provided allocators has improved since
   GSlice was written, and they are now similarly as performant, or more
   performant, than GSlice.
 - The code is unmaintained and nobody understands it.
 - It doesn’t integrate with tooling and system security features which
   have been written for the system `malloc()` implementation (such as
   sanitisers, valgrind, etc.).
 - It’s confusing for developers: should they use `g_slice_new()` or
   `g_new()`?
 - GSlice is faster than the libc allocator for allocating and
   (particularly) freeing linked lists, but since these are a rubbish
   data structure, that’s not a great thing to optimise for.

For the cases where application performance is negatively impacted by
the implementation of GSlice being dropped (and we don’t think there’ll
be many), applications can use a drop-in `malloc()` replacement which is
more suited to their particular workload. Choosing an allocator in GLib
to suit all application workloads is not possible.

Including documentation updates and cleanups by Philip Withnall.

Fixes: #1079
2023-01-25 13:49:09 +00:00
Matthias Clasen
58dd3d3965 Add g_string_free_and_steal 2023-01-19 14:47:11 +00:00
Philip Withnall
73fa684e30 Merge branch 'ptr-array-sort-values' into 'main'
garray: Add g_ptr_array_sort_values[_with_data]() wrappers

See merge request GNOME/glib!3155
2023-01-06 12:09:37 +00:00
Marco Trevisan (Treviño)
0ffd23cac4 garray: Add g_ptr_array_sort_values[_with_data]() wrappers
Historically GPtrArray made possible to compare pointers of pointers values
that it holds, however this is inconvenient in most cases as it requires
wrapper functions and not friendly castings.

So, add two functions that allow to perform the comparisons between the
pointer values that a GPtrArray holds following the same syntax that we
share everywhere in the codebase.
2023-01-06 11:46:01 +00:00
Philip Withnall
5e378c775a Merge branch 'ptr-array-new-take' into 'main'
garray: Add more G(Ptr)Array constructors to take or copy C arrays

See merge request GNOME/glib!3128
2022-12-21 18:34:13 +00:00
Marco Trevisan (Treviño)
b15040215a garray: Add g_array_new_take() and g_array_new_take_zero_terminated()
Make it easy to handle C arrays using GArray API stealing data from other
sources.
2022-12-21 11:40:39 +00:00
Marco Trevisan (Treviño)
670c1f4173 garray: Add g_ptr_array_new_from_null_terminated_array()
It allows to create a GPtrArray from a null-terminated C array computing its
size and in case performing copies of the its values using the provided
GCopyFunc.
2022-12-19 20:37:50 +01:00
Marco Trevisan (Treviño)
c5aedc88fc garray: Add g_ptr_array_new_from_array() to copy a C array
It makes it easier (and more optimized) to create a GPtrArray from a C-style
array of pointers, in case using a GCopyFunc to duplicate the elements.
2022-12-19 20:37:49 +01:00
Marco Trevisan (Treviño)
d5efa78a12 garray: Add g_ptr_array_new_take_null_terminated()
Similar to g_ptr_array_new_take() but it also computes the length of a
zero-terminated array.
2022-12-19 20:05:30 +01:00
Marco Trevisan (Treviño)
14ded2ef94 garray: Add g_ptr_array_new_take() to take a C array without copies
GPtrArray is a nice interface to handle pointer arrays, however if a classic
array needs to be converted into a GPtrArray is currently needed to manually
go through all its elements and do new allocations that could be avoided.

So add g_ptr_array_new_take() which steals the data from an array of
pointers and allows to manage it using the GPtrArray API.
2022-12-19 19:55:28 +01:00
Philip Withnall
abd76e0286 Merge branch 'ghash-keys+values-arrays' into 'main'
ghash: Add APIs to get (and steal) hash table keys and values as GPtrArray

See merge request GNOME/glib!3130
2022-12-16 18:32:10 +00:00
Marco Trevisan (Treviño)
d68e7bc84a ghash: Add functions to steal all keys and values preserving ownership
Add functions to steal all the keys or values from a ghash (especially
useful when it's used as a set), passing the ownership of then to a
GPtrArray container that preserves the destroy notify functions.
2022-12-16 18:45:36 +01:00
Marco Trevisan (Treviño)
d2c3f7f513 ghash: Add APIs to get hash table keys and values as GPtrArray
GPtrArray's are faster than lists and provide more flexibility, so add
APIs to get hash keys and values using these containers too.

Given that we know the size at array initialization we can optimize the
allocation quite a bit, making it faster than the API using GList both at
creation time and for consumers.
2022-12-16 18:45:36 +01:00
Lars Uebernickel
89a7bbcf6e gmenumodel: disallow exporting large menus on the bus
This solves problems with validating untrusted inputs from D-Bus, where
invalid numbers of added and removed menu entries, and positions, could
be specified.

Original patch from
https://bugzilla.gnome.org/show_bug.cgi?id=728733#c7, tweaked by Philip
Withnall to add a few code comments and make
`G_MENU_EXPORTER_MAX_SECTION_SIZE` public so callers can check their
inputs against it if they want. Also tweaked to use `g_warning()` instead
of the nonexistent `g_dbus_warning()`.

Fixes: #861
2022-12-14 15:42:14 +00:00
Emmanuele Bassi
782b5cbee5 Merge branch 'mkenums-docs' into 'main'
docs: Remove a stray > in the glib-mkenums man page

See merge request GNOME/glib!3112
2022-12-13 17:15:33 +00:00
Philip Withnall
c27b02ace7 Merge branch 'gio-thumbnail-sizes' into 'main'
file-info: Add a set of attributes for large thumbnails

Closes #621

See merge request GNOME/glib!2918
2022-12-08 09:04:45 +00:00
Matthias Clasen
f0606d5421 file-info: Add a set of attributes for large thumbnails
Some applications (eg., gnome-photos) really want a large thumbnail,
if one can be created. Simply falling back to a smaller one (probably
created by an old nautilus), without giving the application a chance
to create a bigger thumbnail, is undesirable because they will appear
fuzzy.

Therefore, at separate attribute sets for all the thumbnail sizes
that are supported in the spec: normal/large/x-large/xx-large.

The old attribute will now return by default the biggest available, as
it used to be, but also including the x-large and xx-large cases.

Co-Authored-by: Marco Trevisan <mail@3v1n0.net>

Fixes: #621
2022-12-08 05:21:19 +01:00
Philip Withnall
ddae990509 docs: Remove a stray > in the glib-mkenums man page
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-12-07 08:17:17 +00:00
Philip Withnall
b4231844a2 Revert "build: Use fs.copyfile() instead of configure_file()"
This reverts commit 19353017a7.

The freedesktop SDK, which is used by gnome-build-meta, only has Meson
0.63. Bumping GLib’s Meson dependency to 0.64 means that, at the moment,
GLib is not buildable in gnome-build-meta and hence can’t be tested in
nightly pipelines against other projects, etc.

That’s bad for testing GLib.

It’s arguably bad that we’re restricted to using an older version of
Meson than shipped by Debian Testing, but that’s a separate discussion
to be had.

Revert the Meson 0.64 dependency until the freedesktop SDK ships Meson ≥
0.64. This also means reverting the simplifications to use of
`gnome.mkenum_simple()`.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3077#note_1601064
2022-11-24 12:09:55 +00:00
Xavier Claessens
6dd5c5002a Merge branch 'wip/pwithnall/meson-0.64' into 'main'
build: Bump Meson dependency to 0.64.0

See merge request GNOME/glib!3077
2022-11-23 11:48:51 +00:00
Philip Withnall
19353017a7 build: Use fs.copyfile() instead of configure_file()
Because Meson complains about using `configure_file(copy: true)`.

Includes improvements by Xavier Claessens.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-23 10:40:32 +00:00
Marco Trevisan
ad755e7489 Merge branch 'c-cxx-std-versions' into 'main'
Expose C and C++ standard versions and add macros to check them

See merge request GNOME/glib!2895
2022-11-22 21:10:34 +00:00
Philip Withnall
8d77591d89 build: Deprecate -Druntime_libdir option
It’s been broken since we ported to Meson and nobody has complained, so
let’s deprecate it this cycle and remove it in GLib ≥ 2.78.

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

Fixes: #2786
2022-11-22 16:31:28 +00:00
Marco Trevisan (Treviño)
633561ada2 macros: Add a generic way to get and check the supported C standard
Try to get the value of __STDC_VERSION__ if supported, if not just
fallback to the oldest standard that any compiler should handle.
2022-11-22 17:23:14 +01:00
Marco Trevisan (Treviño)
f9845abe39 gmacros: Define G_CXX_STD_VERSION and check macros
Sadly, in C++ there's not an universal way to get what language standard
is used to compile GLib-based programs, in fact while most compilers
relies on `__cplusplus`, MSVC is defining that, but it does not use it
to expose such information (unless `/Zc:__cplusplus` arg is used).
On the other side, MSVC reports the language standard via _MSVC_LANG [1].

This complication makes us defining some macros in a very complex way
(such as glib_typeof()), because we need to perform many checks just to
understand if a C++ compiler is used and what standard is expecting.

To avoid this, define multiple macros that can be used to figure out
what C++ standard is being used.

[1] https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170
2022-11-21 20:58:54 +01:00
Matthias Clasen
fd0dd9e93c gobject: Add G_TYPE_FLAG_DEPRECATED
This can be used to mark entire types as deprecated,
and trigger a warning when they are instantiated
and `G_ENABLE_DIAGNOSTIC=1` is set in the environment.

There's currently no convenient macros for defining
types with the new flag, but you can do:

```c
_G_DEFINE_TYPE_EXTENDED_BEGIN (GtkAppChooserWidget,
                               gtk_app_chooser_widget,
                               GTK_TYPE_WIDGET,
                               G_TYPE_FLAG_DEPRECATED)
...
_G_DEFINE_TYPE_EXTENDED_END ()
```

Includes a unit test by Philip Withnall.
2022-11-09 12:07:31 +00:00
Philip Withnall
1e7b20d68a Merge branch 'variant-spec-updates' into 'main'
docs: Add licensing/copyright data to GVariant specification and fix various formatting issues

See merge request GNOME/glib!3048
2022-11-08 16:13:59 +00:00
Philip Withnall
b7c497eedb docs: Fix a broken link in the GVariant Specification
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
e039a30ef1 docs: Add a manual revision history to the GVariant Specification
This will make it clear what the bigger changes are between versions.
Kind of like a `NEWS` file for the specification.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
f518d78fd7 docs: Add links to the D-Bus specification to the GVariant Specification
This should clarify object paths and signatures a little, if anyone
needs that. This introduces no semantic changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
227bb51a74 docs: Change ‘DBus’ to ‘D-Bus’ in the GVariant Specification
That’s how it’s meant to be formatted.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
bf4bab98f7 docs: Fix forall formatting in GVariant Specification
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
106ef532fc docs: Improve Python code snippet formatting in GVariant Specification
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
fa823ea3b4 docs: Minor improvement of word choice in the GVariant Specification
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
950e8991cd docs: Remove another dangling reference from the GVariant Specification
This is another reference to an omitted part of Allison’s thesis.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
6d8349a9ff docs: Fix subsection capitalisation consistency in GVariant Spec
The other subheadings here are in Title Case.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
59620c9cf8 docs: Fix a cross-reference to a Figure in the GVariant Specification
reStructuredText doesn’t support cross-references unless always built
with Sphinx (as I understand it). `rst2html5` doesn‘t support them.

So reword this (currently manual) cross-reference so it’s less awkward.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
aa568abb97 docs: Fix a minor typo in the GVariant Specification
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
ca45f84789 docs: Fix references to omitted requirements in GVariant Specification
I believe the specification was originally a shorter extract of
Allison’s thesis. This left a few dangling references to requirements
which were listed in a part of the thesis not included in the
specification.

Reword them slightly so they’re not quite so awkward.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
e34fdb0cd5 docs: Add licensing/copyright data to GVariant specification
The licensing for the original GVariant specification was not specified
in the original PDF.

However, CC-BY-SA-3.0 has been agreed by Allison, the sole copyright
holder, here:

https://gitlab.gnome.org/Teams/documentation/developer-www/-/merge_requests/108/#note_1586866

The diagrams were redrawn by me, so their licensing/copyright status is
clear.

Tested with `reuse lint` to ensure the data is machine-readable.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-08 15:46:16 +00:00
Philip Withnall
9ebb491d55 Revert "meson: Define G_OS_DARWIN when compiling under OSX or iOS"
This reverts commit e85635daa0.

See the previous revert for rationale.

Fixes: #2802
2022-11-07 11:30:32 +00:00
Philip Withnall
0e9e51767a Merge branch 'variant-docs' into 'main'
docs: Convert GVariant Specification to reStructuredText

See merge request GNOME/glib!3044
2022-11-02 09:40:24 +00:00
Emmanuele Bassi
c33edff7fa Apply 2 suggestion(s) to 1 file(s) 2022-11-01 17:38:22 +00:00
Philip Withnall
088df783c0 docs: Convert GVariant Specification to reStructuredText
This is a verbatim conversion of the GVariant Specification from
https://people.gnome.org/~desrt/gvariant-serialisation.pdf /
https://raw.githubusercontent.com/ostreedev/gvariant-rs/master/docs/gvariant-serialisation.pdf
to reStructuredText.

This is for several reasons:
 1. The canonical copy has gone offline due to people.gnome.org being
    shut down.
 2. GLib is the reference implementation of GVariant, so should probably
    host the specification (unless someone wants to host it on
    freedesktop-specs).
 3. Moving it out of a PDF and into reStructuredText should allow for
    amendments. The specification has a few problems, typos and
    oversights in its original form, and it would be good to canonically
    fix them without having to write a separate addendum document.

This conversion is verbatim, and does not change the content of the
document at all, even to fix typos and broken links (which there are a
small number of in the PDF).

This describes what I’m labelling as version 1.0 of the GVariant
serialisation format. Updates to the specification can bump this version
number, in subsequent commits.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-01 13:12:53 +00:00
Matthias Clasen
99c7d60869 gtask: Add g_task_set_static_name()
Similar to g_source_set_static_name, this avoids
strdup overhead for debug-only information in
possibly hot code paths.

We also add a macro wrapper for g_task_set_name that
uses __builtin_constant_p to decide whether to use
g_task_set_name or g_task_set_static_name.
2022-11-01 11:48:38 +00:00
Robert Ancell
568763e776 gio: Create a sandbox checking function 2022-11-01 10:20:36 +00:00
Marco Trevisan (Treviño)
b9e085537d meson: Expose library build type as global variables
Given that it can be computed using an error-prone strings comparisons it
is better to provide a variable everywhere, so that we don't have the
risk of comparing values that are always false.
2022-10-31 14:08:31 +01:00
Simon McVittie
b393413321 gstdio: Add g_clear_fd() and g_autofd
Inspired by libglnx's glnx_close_fd() and glnx_autofd, these let us
have the same patterns as g_clear_object() and g_autoptr(GObject), but
for file descriptors. g_clear_fd() is cross-platform, while g_autofd
is syntactic sugar requiring a supported compiler (gcc or clang).

Now that g_close() checks for EBADF as a programming error, we can
implement the equivalent of glnx_autofd as an inline function without
needing to have errno and EBADF in the header file.

g_clear_fd() is like glnx_close_fd(), but with error checking.
The private _g_clear_fd_ignore_error() function used to implement
g_autofd is a closer equivalent of glnx_close_fd().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-26 19:05:33 +01:00
Marco Trevisan (Treviño)
e85635daa0 meson: Define G_OS_DARWIN when compiling under OSX or iOS
It has enough differences to expose it as an unix-subtype.
2022-10-20 03:37:03 +02:00
Philip Withnall
5215463a03 Merge branch 'wip/chergert/g_set_str' into 'main'
strfuncs: add g_set_str()

Closes #2747

See merge request GNOME/glib!2927
2022-10-15 22:30:18 +00:00
Marco Trevisan (Treviño)
60c935a9c4 gboxed: Add GBookmarkFile as Boxed types
Now that we've a copy function we can define it as a boxed type, making
it fully introspectable.
2022-10-14 16:40:56 +01:00
Marco Trevisan (Treviño)
2e8375daa0 gbookmarkfile: Add copy function
GBookmarkFile has everything for being introspectable, but it lacks a
GType, because it can't be copied. So provide a copy function that
deeply copies all the bookmark structures.

Add tests for this.
2022-10-14 16:39:20 +01:00
Christian Hergert
49ae9b490d strfuncs: add g_set_str()
This is like our other suite of g_set_*() based APIs to simplify and
improve correctness of setters for fields, properties, and more.

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

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

Fixes #2747
2022-10-14 16:24:41 +01:00
Philip Withnall
05714bf635 docs: Add 2.76 release series documentation pages to the build
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-14 16:03:29 +01:00
Xavier Claessens
dcfc9f689e Fix symbol visibility macros on Windows
There is currently no `dllimport` attribute on any of our function,
which prevents MSVC to optimize function calls.

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

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

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

This leaves only API index to add manually into glib-docs.xml when
bumping GLib version. That file cannot be generated because Meson does
not allow passing a buit file to gnome.gtkdoc()'s main_xml kwarg
unfortunately.
2022-10-13 20:53:56 -04:00
Emmanuele Bassi
32edf9c01a Build API docs only with shared libraries
Building the references requires libraries with all their symbols
available. Passing `-Dgtk_doc=true` and `-Ddefault_library=static`
should be considered a configuration error.
2022-09-14 15:03:43 +01:00
Marco Trevisan (Treviño)
ea0617e993 docs: Add --delete option to gio-tool attributes documentation
It was added via !2845 but not documented.
2022-08-05 22:36:06 +02:00
Michael Catanzaro
61a843564d Improve default value of glib_debug option
glib_debug is an auto option. This is clever because it allows us to
guess the best default based on the build type, while also allowing an
easy way to override if the guess is not good. Sadly, the attempt to
guess based on the build type does not work well. For example, it
considers debugoptimized builds to be debug builds, but despite the
name, it is definitely a release build type (except on Windows, which
we'll ignore here). The minsize build type has the exact same problem.
The debug option is true for both build types, but this only controls
whether debuginfo is enabled, not whether debug extras are enabled.

The plain build type has a different problem: debug is off, but the
optimization option is off too, even though plain builds are distro
builds are will almost always use optimization.

I've outlined an argument for why we should make these changes here:
https://blogs.gnome.org/mcatanzaro/2022/07/15/best-practices-for-build-options/

Specifically, Rule 4 shows all the build types and whether they
correspond to release builds or debug builds. Rule 6 argues that we
should provide good defaults for plain builds.
2022-08-03 17:07:13 -05:00
Aleksei Rybalkin
8d5a44dc8f replace pcre1 with pcre2 2022-07-12 11:46:34 +00:00
Philip Withnall
8385f52db7 Merge branch 'inline-macros' into 'main'
gmacros: Provide platform-independent G_ALWAYS_INLINE and G_NO_INLINE

See merge request GNOME/glib!2781
2022-07-06 13:40:10 +00:00
Marco Trevisan (Treviño)
15cd0f0461 gmacros: Provide platform-independent G_ALWAYS_INLINE and G_NO_INLINE
We had gcc-only implementations for them while both can be used in all
the supported platforms we have.

So let's just provide generic definitions, while we keep the old ones
for both consistency and retro-compatibility.
2022-07-06 14:57:06 +02:00
Emmanuele Bassi
fa05ebe27c docs: Mention alternatives for defining enumeration types
We should mention glib-mkenums in the documentation for
G_DEFINE_ENUM_TYPE and G_DEFINE_FLAGS_TYPE.

We should also mention the macros in the documentation for glib-mkenums.

This way, developers can choose the most appropriate tool for their use
case.
2022-06-30 01:46:54 +01:00
Emmanuele Bassi
28edd84e77 docs: Add the new G_DEFINE macros for enumeration types 2022-06-30 01:46:54 +01:00
Philip Withnall
e5ccbe09da Merge branch 'atomic-exchange-pre-value' into 'main'
gatomic: Add Compare and Exchange functions that returns the previous value

See merge request GNOME/glib!2766
2022-06-23 13:19:05 +00:00
Philip Withnall
5655af6ada Merge branch 'more-async-gfile' into 'main'
gfile (and GAppInfo): Add some missing async APIs and ensure async calls always use them

See merge request GNOME/glib!2717
2022-06-23 11:49:55 +00:00
Marco Trevisan (Treviño)
bfdeb37f6e gatomic: Add Compare and Exchange functions that returns the previous value
Atomic primitives allow to do conditional compare and exchange but also
to get the value that was previously stored in the atomic variable.

Now, we provided an exchange function that allows to do an exchange if
the atomic value matches an expected value but we had no way to know
at the same time what was the value in the atomic at the moment of the
exchange try, an this can be useful in case that the operation fails,
for example if the current value is still acceptable for us, allowing
to do a kind of "OR" check:

  gint old_value;
  gint valid_value = 222;
  while (!g_atomic_pointer_compare_and_exchange_value (&atomic,
                                                       valid_value, 555,
                                                       &old_value)
    {
      if (old_value == 555 || old_value == 222)
        valid_value = old_value;
    }
2022-06-22 23:01:19 +02:00
Marco Trevisan (Treviño)
8aee5fc628 GAppInfo: Add async API to get default Application for URI scheme
Make possible to fetch the default application for URI scheme in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
44dbd43170 GAppInfo: Add async API to get default Application for content type
Make possible to fetch the Application for default content type in a
thread without using blocking I/O.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
22e951e6ac gfile: Add Async API to create a temporary directory and return as GFile
While it's possible to create a directory synchronously via
g_dir_make_tmp(), there's no such API that performs it asynchronously.

So implement it using GFile, using a thread to perform such task.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
fa24391529 gfile: Add API to create a new temporary file asynchronously
Make possible to create a new gfile with a temporary name in async
way, using the same API of g_file_new_tmp().
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
b64fd312da gerror: Add an utility function to get the GIO Error from GFileError
When GIO functions are using GLib file utils functions we expect to
return a GIO Error, so provide a way to map such error values.
2022-06-22 20:07:25 +02:00
Eli Schwartz
24ec80cfb4
meson: simplify iconv lookups using Meson's builtin dependency lookup
iconv is complicated to look up. That complexity now resides in
Meson, since 0.60.0, via a `dependency('iconv')` lookup, so use that
instead.

No effort is made to support the old option for which type of iconv to
use. It was a false choice, because if only one was available, then
that's the only one you can use, and if both are available, the external
iconv shadows the builtin one and renders the builtin one unusable,
so there is still only one you can use.

This meant that when configuring glib with -Diconv=libc on systems that
had an external iconv, the configure check would detect a valid libc
iconv, try to use it, and then fail during the build because iconv.h
belongs to the external iconv and generates machine code using the
external iconv ABI, but fails to link to the iconv `find_library()`.
Meson handles this transparently.
2022-06-16 12:04:59 -04:00
Philip Withnall
b3f49d08a6 build: Move gvdb to a subproject
Rather than carrying the copylib around inside GLib, which is a pain to
synchronise and affects our code coverage statistics.

This requires updating the CI images to cache the new subproject,
including updating the `cache-subprojects.sh` script to pull in git
submodules.

It also requires adding `gioenumtypes_dep` to be added to the
dependencies list of `libgio`, since it needs to be build before GVDB as
it’s pulled in by the GIO headers which GVDB includes.

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

Helps: #2603
2022-06-16 10:12:07 +01:00
Marco Trevisan (Treviño)
04718a9692 gfile: Implement interface API to make symbolic links asynchronously
The interface was ready for this API but it was not provided.

So implement this, using a thread that calls the sync API for now.

Add tests.

Helps with: GNOME/glib#157
2022-06-15 19:49:38 +02:00
Marco Trevisan (Treviño)
fa4e34667c gatomic: Add APIs to perform atomic int / pointer exchanges
Atomic APIs provide a way to exchange values only if we compare a value
that is equal to the old value, but not to just exchange the value
returning the old one.

However, compilers provide such built-in functions, so we can use them
to expose such functionality to GLib.

The only drawback is that when using an old version of gcc not providing
atomic APIs to swap values, we need to re-implement it with an
implementation that may not be fully atomic, but that is safe enough.

However this codepath should really not be used currently as gcc
introduced __atomic_exchange_n() at version 4.7.4, so 8 years ago.
2022-06-07 17:10:57 +02:00
nitinosiris
b33ef610de Add functionality to preserve nanosecond timestamps
file copy doesn't preserve nanosecond timestamps

Closes #369
2022-05-27 17:03:35 +01:00
Thomas Haller
ee247c0a2d array: add support for %NULL termination in GPtrArray
GArray supports a "zero_terminated" flag, but GPtrArray doesn't.
This is odd, because especially for a pointer array it makes sense
to have a %NULL sentinel. This would be for example useful to track
or construct a strv array with a GPtrArray.

As workaround for this missing feature you could use a GArray instead
(ugly) or to explicitly add the %NULL element. However the latter increases
the "len" of the array, which can be problematic if you want to still use
the GPtrArray for other purposes.

Add API for marking a GPtrArray as %NULL terminated. In that case, the
API will ensure that there is always a valid %NULL sentinel after the
array. Note that the API does not enforce that a %NULL terminated API
actually has any data allocated. That means, even with a %NULL terminated
array, pdata can still be %NULL (only if len is zero).

Add g_ptr_array_new_null_terminated() constructor. The null-terminated flag
cannot be cleared. Once the GPtrArray is flagged to be %NULL terminated, it
sticks. The purpose is that once a user checks whether a GPtrArray instance
is safe to be treated as a %NULL terminated array, the decision does
not need to be re-evaluated.

Also add a g_ptr_array_is_null_terminated(). That is useful because it
allows you to check whether a GPtrArray created by somebody else is safe
to use as a %NULL terminated array. Since there is no API to make an
array not %NULL terminated anymore, this is not error prone.

The new flag is tracked as a guint8 in GRealPtrArray. On common 64 bit
architectures this does not increase the size of the struct as it fits
in an existing hole. Note that this is not a bitfield because it's
probably more efficient to access the entire guint8. However, there is
still a 3 bytes hole (on common 32 and 64 architectures), so if we need
to add more flags in the future, we still have space for 24 bits,
despite the new flag not being a bitfield.

The biggest downside of the patch is the runtime overhead that most
operations now need to check whether %NULL termination is requested.

Includes some tweaks and additional tests by Philip Withnall.

https://gitlab.gnome.org/GNOME/glib/-/issues/353
2022-05-27 15:27:19 +01:00
Philip Withnall
93bf87528d Merge branch 'ebassi/source-once' into 'main'
Add one-shot idle and timeout functions

See merge request GNOME/glib!2684
2022-05-27 12:25:51 +00:00
Emmanuele Bassi
12571a0821 Add one-shot idle and timeout functions
Many idle and timeout sources are installed as "one shot": called once
and immediately removed. While it's easy to write a simple callback that
returns G_SOURCE_REMOVE, it would also be useful to have some sort of
"visual" marker when reading the code; a way to immediately see that a
callback (which may be defined elsewhere in the code) is meant to be
invoked just once.

Includes additional unit tests by Philip Withnall.
2022-05-27 12:57:55 +01:00
Matthias Clasen
dacfe8c88a param: Add g_param_value_is_valid
This is wrapper for the new value_is_valid vfunc,
but it falls back to using value_validate to
obtain the same information.
2022-05-23 15:48:28 -04:00
Matthias Clasen
0415bf9412 Add g_datalist_id_remove_multiple
This is more efficient than calling
g_datalist_id_remove() multiple times
in a row, since it only takes the locks
once.

Allow up to 16 keys to be removed in one go.
That is enough for the use we have in GObject,
and it avoids any danger of blowing the stack.
2022-05-23 09:19:45 -04:00
Matthias Clasen
aaef7f30b3 value: Add G_VALUE_COLLECT_INIT2
Add a variant of the G_VALUE_COLLECT_INIT() macro
that provides the GTypeValueTable to the caller.
2022-05-23 05:57:36 -04:00
Philip Withnall
8f9c5090db docs: Use G_PARAM_STATIC_STRINGS in examples and explain it more
Make it a bit clearer in the documentation that using
`G_PARAM_STATIC_STRINGS` everywhere is a good thing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-20 12:57:36 +01:00
Philip Withnall
136ccf10f8 docs: Don’t ignore gunixfdlist.h when building docs on Windows
Since 5efb84f24, it’s available on all platforms.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-18 23:36:06 +01:00
Philip Withnall
768c87697e build: Specify all inputs to concat-files-helper.py
Since Meson 0.52, a list of inputs is correctly supported, so our
workaround can be removed.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-17 14:04:24 +01:00
Xavier Claessens
5942103937 meson: Use range() instead of listing all stable versions
Note that range(), like in python, has start value included and stop
value excluded. That's why we use last_version + 2.
2022-05-11 14:34:00 -04:00
Philip Withnall
25ab87d8e5 build: Drop checks and workarounds for older Meson versions
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-06 13:01:44 +01:00
Philip Withnall
e2426dd74d Merge branch 'list-store-equal-full' into 'main'
gio: Add g_list_store_find_with_equal_func_full()

Closes #2447

See merge request GNOME/glib!2549
2022-04-05 18:02:15 +00:00
Jason Francis
a85246af3b gio: Add g_list_store_find_with_equal_func_full()
Fixes: #2447
2022-04-05 18:34:39 +01:00
Jason Francis
2a842b1173 gobject: Add g_signal_group_connect_closure 2022-04-05 15:32:20 +01:00
Philip Withnall
4f79f0712c gversionmacros: Add version macros for GLib 2.74
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-28 12:55:20 +01:00
Philip Withnall
6aa210e6af gio: Remove fam file monitor support
libgamin was last released in 2007 and is dead
[upstream](https://gitlab.gnome.org/Archive/gamin). Distributions may
still ship it (although Fedora no longer does), but we want people to
use inotify on Linux since it’s actively supported.

BSDs use kqueue. Windows uses win32filemonitor.

FAM might still be used on some commercial Unix distributions, but there
are no contributors from those distributions, and certainly no CI for
them to prevent regressions.

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

Fixes: #2614
2022-03-23 15:41:54 +00:00
Philip Withnall
2759dd71be gio: Remove remaining references to fen file monitor
It used to exist on Solaris, but GLib’s support for it was mostly
removed in 2015 in commit 21ab660cf8.

Remove the final few references.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-23 15:40:41 +00:00
Philip Withnall
e951bf1ae3 docs: Improve formatting for some file monitor documentation
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-23 15:34:19 +00:00
Philip Withnall
bbf1dca06a docs: Drop reference to G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME
Support for separate directory monitors was dropped in commit
b995c08bf3, in 2015.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-03-23 15:32:37 +00:00
Philip Withnall
b5873878cd Merge branch '1190-debugging-docs' into 'main'
gdebugcontroller: Add documentation and tests

Closes #1190

See merge request GNOME/glib!2486
2022-02-15 12:47:50 +00:00
Philip Withnall
1b3e6bab53 gdebugcontrollerdbus: Add stop() method
This allows the controller to explicitly be removed from the bus, in a
way that allows the caller to synchronise with it and know that all
other references to the controller should have been dropped (i.e. after
this method returns, there should be no in-flight D-Bus calls still
holding a reference to the object).

This is needed to be able to guarantee finalisation of the controller in
unit tests (and comparable real-world situations).

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

Helps: #1190
2022-02-14 14:42:17 +00:00
Emmanuele Bassi
7bc6ef8734 Do not generate C resources for all possible toolchains
The resources data is generated for both GCC and MSVC toolchains, even
though we know beforehand which toolchain we're going to compile it for.
By dropping the data duplication we make the generated resources file
faster to compile, especially when dealing with large embedded data,
instead of relying on the C pre-processor to walk the whole file and
discard the branch we're not using.
2022-02-14 13:09:22 +00:00
Philip Withnall
f9c08308ea Merge branch 'ebassi/aligned-alloc' into 'main'
Add aligned memory allocators

Closes #2574

See merge request GNOME/glib!2421
2022-02-11 15:04:25 +00:00
Emmanuele Bassi
475d574440 Add aligned memory allocators
When working with storage (especially GInputStream or GOutputStream) it
is preferred to use page-aligned buffers so that the operating system
can do page-mapping tricks as the operation passes through the kernel.

Another use case is allocating memory used for vectorised operations,
which must be aligned to specific boundaries.

POSIX and Windows, as well as the C11 specification, provide this kind
of allocator functions, and GLib already makes use of it inside GSlice.
It would be convenient to have a public, portable wrapper that other
projects can use.

Fixes: #2574
2022-02-11 14:44:09 +00:00
Philip Withnall
29edfc1169 gdebugcontroller: Drop dup_default() method as it’s broken
If `GDebugControllerDBus` remains as the only, or default,
implementation of `GDebugController`, `dup_default()` cannot work.
`GDebugControllerDBus` requires a `GDBusConnection` at construction
time, which the `GIOModule` construction code can’t provide it.

Either we use a default D-Bus connection (but which one? and how would
it be changed by the user later if it was the wrong one?), or delegate
singleton handling of the `GDebugController` to the user.

The latter approach seems more flexible.

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

Helps: #1190
2022-02-10 19:21:24 +00:00
Philip Withnall
50d23f9680 Merge branch 'feature/move_async' into 'main'
Implement async file movement

See merge request GNOME/glib!2469
2022-02-07 14:29:52 +00:00
Lucas Schwiderski
eeb2bcf5a9 Implement async file movement 2022-02-07 14:03:47 +00:00
Christian Hergert
dd43471f60 gobject: add GSignalGroup
Much like GBindingGroup, the GSignalGroup object allows you to connect many
signal connections for an object and connect/disconnect/block/unblock them
as a group.

This is useful when using many connections on an object to ensure that they
are properly removed when changing state or disposing a third-party
object.

This has been used for years in various GNOME projects and makes sense to
have upstream instead of multiple copies.
2022-02-01 17:09:14 -08:00
Christian Hergert
0d9de09192 gobject: add GBindingGroup
Originally, GBindingGroup started with Builder as a way to simplify all
of the third-degree object bindings necessary around Model-Controller
objects such as TextBuffer/TextView.

Over time, it has grown to be useful in a number of scenarios outside
of Builder and has been copied into a number of projects such as GNOME
Text Editor, GtkSourceView, libdazzle, and more.

It makes sense at this point to unify on a single implementation and
include that upstream in GObject directly alongside GBinding.
2022-01-28 16:01:22 -08:00
Philip Withnall
7f519624e2 Merge branch '1190-debug-interface' into 'main'
gdebugcontroller: Add debug controller API and D-Bus implementation

Closes #1190

See merge request GNOME/glib!2330
2022-01-27 11:00:40 +00:00
Philip Withnall
0c8f7de55a gdebugcontroller: Add debug controller API and D-Bus implementation
This is intended to provide a uniform interface for controlling whether
the debug output from an application (or service) is emitted, typically
to journald, but actually to wherever the application chooses to output
it.

The main implementation of `GDebugController` is `GDebugControllerDBus`,
which is intended to be used on Linux. Other implementations may be
added in future for other platforms, or larger applications may want to
provide their own implementation which integrates with their ecosystem.

The `GDebugControllerDBus` implementation exposes a D-Bus interface at
`/org/gtk/Debugging` with a method to enable or disable debug
output at runtime.

This could be used by external harnesses, such as GNOME Builder or
systemd, to give a uniform way to get debug output from an application.

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

Fixes: #1190
2022-01-26 15:19:27 +00:00
Philip Withnall
bb4bec0921 gmessages: Expose a property for enabling debug message output
This is an API analogue of the G_MESSAGES_DEBUG environment variable. It
is intended to be exposed outside applications (for example, as a D-Bus
interface — see follow-up commits) so that there is a uniform interface
for controlling the debug output of an application.

Helps: #1190
2022-01-26 15:17:02 +00:00
Marc-André Lureau
83d45c4f35 gio: compile GUnixConnection on all platforms
On !UNIX, return an error for send_fd() & receive_fd().
(the unixfdmessage unit is not compiled on !UNIX)

The header is installed under the common GIO include directory.

Ensure G_TYPE_UNIX_CONNECTION is registered on all platforms.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-01-26 18:19:44 +04:00
Marc-André Lureau
af1777d3d3 meson: compile GUnixCredentialsMessage on all platforms
The header is now also installed under the common GIO include directory.

Sorry if it breaks any build, you had to use the correct header path.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-01-26 18:19:44 +04:00
Marc-André Lureau
3308cfb020 gio: compile GUnixSocketAddress on all platforms
Move the header under the common GIO include directory.

Sorry if it breaks any build, you had to use the correct header path.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-01-26 18:19:44 +04:00
Marc-André Lureau
4339192b53 gio: add fallback afunix.h header
afunix.h is only recently distributed with Windows SDK & MinGW.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-01-26 18:19:23 +04:00
Emmanuele Bassi
1437be8049 docs: Add --generate-rst to the gdbus-codegen docs 2022-01-22 01:30:16 +00:00
Philip Withnall
3be0fc867e Merge branch 'wip/hash-table-from' into 'main'
ghash: Add g_hash_table_new_similar

See merge request GNOME/glib!2405
2022-01-19 11:19:07 +00:00
Jonas Ådahl
283d9e0c15 ghash: Add g_hash_table_new_similar()
This function creates a new hash table, but inherits the functions used
for the hash, comparison, and key/value memory management functions from
another hash table.

The primary use case is to implement a behaviour where you maintain a
hash table by regenerating it, letting the values not migrated be freed.
See the following pseudo code:

```
GHashTable *ht;

init(GList *resources) {
  ht = g_hash_table_new (g_str_hash, g_str_equal, g_free, g_free);
  for (r in resources)
    g_hash_table_insert (ht, strdup (resource_get_key (r)), create_value (r));
}

update(GList *resources) {
  GHashTable *new_ht = g_hash_table_new_similar (ht);

  for (r in resources) {
    if (g_hash_table_steal_extended (ht, resource_get_key (r), &key, &value))
      g_hash_table_insert (new_ht, key, value);
    else
      g_hash_table_insert (new_ht, strdup (resource_get_key (r)), create_value (r));
  }
  g_hash_table_unref (ht);
  ht = new_ht;
}
```
2022-01-18 22:19:55 +01:00
Alexander Schwinn
28d833a075 Make clear in doc that signals are emitted synchroniously 2022-01-18 08:53:20 +00:00
Patrick Griffis
96ce3feeb9 gtlscertificate: Add ability to load PKCS #12 encrypted files
This depends on the GTlsBackend implementing these properties
2022-01-07 11:27:56 -06:00
Sophie Herold
68eab1d999 utils: Add XDG_STATE_HOME support 2021-12-24 20:11:39 +00:00
Mohammed Sadiq
3bd2ab4550 docs: Improve GVariant docs
Fix a typo and expand examples to include freeing memory
where it's not obvious
2021-11-29 15:24:15 +05:30
Marc-André Lureau
b4631c44ad galloca: Add new API g_alloca0 and g_newa0
Added `g_alloca0()` which wraps `g_alloca()` and initializes
allocated memory to zeroes.

Added `g_newa0()` which wraps `g_alloca0()` in a typesafe manner.

Refreshed and tweaked by Nishal Kulkarni.
2021-11-26 12:24:23 +00:00
Sebastian Dröge
6d8045ddb4 Merge branch 'gdbus-call-interactive' into 'main'
gdbus: Add --interactive option to `gdbus call`

See merge request GNOME/glib!2329
2021-11-22 13:58:46 +00:00
Alvarito050506
03753cda79 Better detection of the cleanup attribute.
Use g_macro__has_attribute to detect it instead of
hardcoding __GNUC__ || __clang__. This adds support
for a few compiler and is consistent with the rest
of the gmacros.h file.
2021-11-16 15:13:07 +00:00
gonyere
5eeac53793 Changed gendered terms to be gender-neutral 2021-11-12 21:32:21 -05:00
Philip Withnall
b75a16b048 gdbus: Add --interactive option to gdbus call
This allows the flag to allow interactive auth to be set. Previously, it
was unconditionally unset.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-11-11 11:26:22 +00:00
Vinícius dos Santos Oliveira
7ba86be594 Add g_main_context_new_with_flags()
This constructor is useful to set options that can't change after
creation.
2021-09-21 14:50:30 +01:00
Philip Withnall
94b74c761d gversionmacros: Add version macros for GLib 2.72
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-09-17 11:35:21 +01:00
Evan Miller
508352339a Fix false deprecation warnings on old GCC/MSVC
Closes #2472
2021-09-07 11:21:20 +01:00
Simon McVittie
a076dbcb68 gtestutils: Allow failing a test with a printf-style message
This allows a pattern like

    g_test_message ("cannot reticulate splines: %s", error->message);
    g_test_fail ();

to be replaced by the simpler

    g_test_fail_printf ("cannot reticulate splines: %s", error->message);

with the secondary benefit of making the message available to TAP
consumers as part of the "not ok" message.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:49:11 +01:00
Simon McVittie
182d9995ca gtestutils: Allow skipping tests with a printf-style message
Forming the g_test_skip() message from printf-style arguments seems
common enough to deserve a convenience function.

g_test_incomplete() is mechanically almost equivalent to g_test_skip()
(the semantics are different but the implementation is very similar),
so give it a similar mechanism for symmetry.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:41:08 +01:00
Bastien Nocera
9645cbffa8 gio: Add portal version of GPowerProfileMonitor 2021-08-13 01:32:31 +02:00
Philip Withnall
709df8eeb4 Merge branch 'docgen-fixes' into 'main'
Adapt documentation to gi-docgen

See merge request GNOME/glib!2206
2021-08-03 13:53:38 +00:00
Guido Günther
791218a5f5 GNotification: Allow to set a category
Some backends like the FDO one allow to set a category. This helps the
notification daemon to select a proper feedback type.
2021-08-02 19:26:38 +02:00
Emmanuele Bassi
6081e92daf docs: Match GZlib(De)Compressor section with the type name
Otherwise the introspection scanner won't be able to match the
documentation stanza to the corresponding type.
2021-08-02 13:27:55 +01:00
Patrick Griffis
889bdb994f Add GPowerProfileMonitor 2021-07-28 15:56:02 +02:00
Emmanuele Bassi
ef15a4e720 docs: Add new symbols 2021-07-27 12:27:53 +01:00
Philip Withnall
ef6a551739 Merge branch 'main' into 'main'
Fix some test suite memory leaks

See merge request GNOME/glib!2195
2021-07-26 10:06:08 +00:00
Matthias Clasen
bb4d390577 mainloop: Add g_source_set_static_name
g_source_set_name duplicates the string, and this is
showing up as one of the more prominent sources of strdups
in GTK profiles, despite all the names we use being literals.

Add a variant that avoids the overhead.
2021-07-24 11:26:40 -04:00
GOUJON Évan
353f0b5235 glib/gtestutils: Introduce and use a g_test_suite_free function 2021-07-23 22:16:44 +02:00
GOUJON Évan
f0c0d8b67c glib/gtestutils: Introduce and use a g_test_case_free function 2021-07-23 22:10:08 +02:00
nitinosiris
ee589aaa32 API: Add g_module_open_full()
g_module_open_full() is wrapper around g_module_open() function
which returns a GError in case of failure.

Closes #203
2021-07-21 21:45:51 +01:00
nitinosiris
75db4883fc GThreadPool: Add g_thread_pool_new_full()
g_thread_pool_new_full() is similar to g_thread_pool_new()
but with GDestroyNotify argument.

Closes #121
2021-07-02 18:42:59 +05:30
Philip Withnall
74595ab64a Merge branch 'wip/pwithnall/962-drop-embedded-pcre' into 'main'
pcre: Drop internal libpcre copy

Closes #962 and #642

See merge request GNOME/glib!2144
2021-06-21 14:07:45 +00:00
Philip Withnall
9570e67744 pcre: Drop internal libpcre copy
It’s no longer used and is a maintenance burden.

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

Fixes: #962
2021-06-16 16:45:10 +01:00
Philip Withnall
9fbd7f3dc1 build: Drop the internal_pcre option in favour of the subproject
This should maintain equivalent functionality, apart from that now you
have to pass `--force-fallback-for libpcre` to `meson configure` in
order to use the subproject; rather than specifying
`-Dinternal_pcre=true` to use the internal copy.

This also fixes #642, as the wrapdb copy of libpcre is version 8.37.

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

Helps: #962
Fixes: #642
2021-06-16 16:45:10 +01:00
Philip Withnall
4d6dbe0904 Merge branch 'g_dbus' into 'main'
gdbus: Add g_dbus_is_error_name() symbol for g_dbus_is_interface_name()

Closes #402

See merge request GNOME/glib!2156
2021-06-16 10:58:04 +00:00
nitinosiris
5b9a8e2048 gdbus: Add g_dbus_is_error_name() symbol for g_dbus_is_interface_name()
Closes #402
2021-06-16 08:05:50 +05:30
Simon McVittie
e0b6b8037d Distinguish more clearly between wait status and exit status
On Unix platforms, wait() and friends yield an integer that encodes
how the process exited. Confusingly, this is usually not the same as
the integer passed to exit() or returned from main(): conceptually it's
an integer encoding of this tagged union:

    enum { EXITED, SIGNALLED, ... } tag;
    union {
        int exit_status;         /* if EXITED */
        struct {
            int terminating_signal;
            bool core_dumped;
        } terminating_signal;    /* if SIGNALLED */
        ...
    } detail;

Meanwhile, on Windows, wait statuses and exit statuses are
interchangeable.

I find that it's clearer what is going on if we are consistent about
referring to the result of wait() as a "wait status", and the value
passed to exit() as an "exit status".

GSubprocess already gets this right: g_subprocess_get_status() returns
the wait status, while g_subprocess_get_exit_status() genuinely returns
the exit status. However, the GSpawn family of APIs has tended to
conflate the two.

Confusingly, g_spawn_check_exit_status() has always checked a wait
status, and it would not be correct to pass an exit status to it; so
let's deprecate it in favour of g_spawn_check_wait_status(), which
does the same thing that g_spawn_check_exit_status() always did.
Code that needs backwards-compatibility with older GLib can use:

    #if !GLIB_CHECK_VERSION(2, 69, 0)
    #define g_spawn_check_wait_status(x) (g_spawn_check_exit_status (x))
    #endif

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-15 14:33:14 +01:00
Philip Withnall
7b6ccc8bdb Merge branch 'range-checked' into 'main'
GBytes: add range-checked pointer getter

Closes #1098

See merge request GNOME/glib!2147
2021-06-15 12:01:12 +00:00
Nitin Wartkar
e3452ea01f GBytes: add range-checked pointer getter
Updated and improved by Nitin Wartkar.

Fixes: #1098
2021-06-15 12:01:11 +00:00
Philip Withnall
b95d9d1db6 Merge branch 'g_obj_take_ref' into 'main'
GObject: add g_object_take_ref()

Closes #1112

See merge request GNOME/glib!2146
2021-06-15 11:28:00 +00:00
Allison Ryan Lortie
3764c6730e GObject: add g_object_take_ref()
This works in the same way as g_variant_take_ref(), and for the same
reason.

Updated and Rebased by Nitin Wartkar <nitinwartkar58@gmail.com>

Closes #1112
2021-06-11 18:13:34 +05:30
Philip Withnall
c0fe89c986 Merge branch 'gtypeof' into 'main'
glib_typeof: Move definition to its own header

See merge request GNOME/glib!1969
2021-06-10 12:26:27 +00:00
Ross Wollman
4d3618cbd1 tls: expose SAN details on GTlsCertificate
This changeset exposes

* `dns-names`
* `ip-addresses`

on GTlsCertificate provided by the underlying TLS Backend.

See https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/165 for the corresponding glib-networking changes.

Relates: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2113
Relates: https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/156/diffs
Relates: https://github.com/microsoft/playwright/issues/6759
2021-06-10 00:54:45 +00:00
Utkarsh Singh
47e161d082 compiling.xml: Don't recommend backticks 2021-06-09 10:13:27 +00:00
Michael Catanzaro
bf37392045 tls: add functions to get protocol version and ciphersuite name
This adds g_tls_connection_get_protocol_version(),
g_tls_connection_get_ciphersuite_name(), and DTLS variants. This will
allow populating TLS connection information in the WebKit web inspector.

This is WIP because we found it's not quite possibly to implement
correctly with GnuTLS. See glib-networking!151.
2021-06-03 10:56:15 -05:00
Philip Withnall
be24b0c622 docs: Wrap a code example more tightly to reduce minimum page width
Otherwise the page has a horizontal scrollbar in Devhelp on some
machines.

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

Fixes: #2414
2021-06-03 12:52:51 +01:00
Michael Catanzaro
7a51163cf9 Merge branch 'feature/cert-info' into 'master'
tls: expose cert details on GTlsCertificate

See merge request GNOME/glib!2113
2021-06-01 20:25:21 +00:00
Ross A. Wollman
a17c28790a tls: expose cert details on GTlsCertificate
This changeset exposes

* `not-valid-before`
* `not-valid-after`
* `subject-name`
* `issuer-name`

on GTlsCertificate provided by the underlying TLS Backend.

In order to make use of these changes,
see the related [glib-networking MR][glib-networking].

This change aims to help populate more of the [`Certificate`][wk-cert]
info in the WebKit Inspector Protocol on Linux.

This changeset stems from work in Microsoft Playwright to [add more info
into its HAR capture][pw] generated from the Inspector Protocol events
and will bring feature parity across WebKit platforms.

[wk-cert]: 8afe31a018/Source/JavaScriptCore/inspector/protocol/Security.json
[pw]: https://github.com/microsoft/playwright/pull/6631
[glib-networking]: https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/156
2021-06-01 16:24:33 +00:00
Dan Williams
9cb1bb0fb2 Add g_prefix_error_literal()
Because sometimes you don't want a lone "%s", and you don't
want the compiler yelling at you about format strings that
don't have any format in them.

Closes #663
2021-05-28 17:15:46 +02:00
alex-tee
232b40da7b gstrvbuilder: add addv and add_many to the API 2021-05-26 12:41:18 +00:00
Xavier Claessens
090d65712d glib_typeof: Move definition to its own header
It is cleaner to define glib_typeof() in a header included after
gversionmacros.h so we can use GLIB_VERSION_MIN_REQUIRED directly
instead of doing it everywhere glib_typeof() is used.
2021-05-17 12:07:30 -04:00
Emmanuel Fleury
2e4524cd36 Add the G_OPTION_ENTRY_NULL macro to properly initialize GOptionEntry arrays 2021-05-13 12:57:06 +02:00
Geyslan G. Bem
8cc03f8cd8 docs: Standardize spelling of serializ*
Changes serialis* to serializ* as proposed in #2399.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
2021-05-07 08:51:22 -03:00
Robin Verdenal-Tallieux
514c2d8197 gmacros: Add __ to noinline to prevent conflict with macro in pixman
Fixes: #2388
2021-05-03 09:37:00 +00:00
Marco Trevisan (Treviño)
fbb198f968 gpattern: Move match and match_string functions into GPatternSpec
This allows introspection to properly handle them as GPatternSpec
methods, as per this deprecate g_pattern_match() and
g_pattern_match_string() functions.
2021-04-27 16:25:09 +02:00
Marco Trevisan (Treviño)
b8a9f4b436 boxed: Register GPatternSpec as boxed type 2021-04-27 16:25:09 +02:00
Marco Trevisan (Treviño)
474ece6d61 gpattern: Implement copy function
Add copy ability for pattern spec, so that it can be used as a boxed
type.
2021-04-27 16:25:09 +02:00
Aleksandr Mezin
2b9bf7b162 gmacros.h: use g_macro__has_attribute() where possible
Fall back to compiler version checks only when `__has_attribute()` is not
available.

clang-cl doesn't define `__GNU__`, but still accepts attributes. This change
gets rid of a lot of warnings when building GLib with clang-cl. For GCC and
non-cl Clang nothing should change.
2021-04-16 14:45:03 +06:00
Chun-wei Fan
35154a3519 glib-sections.txt: Add g_macro__has_extension in private section
This should satisfy the documentation build check.
2021-03-31 10:50:27 +08:00
Abanoub Ghadban
240cc7da97 gfileinfo: Add APIs to get and set {access,creation}_date_time 2021-03-28 23:07:39 +02:00
liuyangming
8fb3101715 gtree: Make g_tree_remove_all() public
g_tree_remove_all is useful and the corresponding function in GHashTable
is exposed, so make this function public is meaningful.
2021-03-23 11:36:57 +00:00
Simon McVittie
6c5a227bcc gmain: Add g_steal_fd() to API
This is basically glnx_steal_fd() from libglnx. We already had two
private implementations of it in GLib.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-22 11:48:10 +00:00
Simon McVittie
1248b642ad gversionmacros: Add version macros for GLib 2.70
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-18 13:58:41 +00:00
Philip Withnall
b31f3f5f80 gspawn: Add new g_spawn_async_with_pipes_and_fds() API
This is a simple wrapper around the new source/target FD mapping
functionality in `fork_exec()`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Joshua Lee
c576a4cd82 string: Add find and replace function
This adds g_string_replace(), a function that replaces instances of one string
with another in a GString. It allows the caller to specify the maximum number
of replacements to perform, and returns the number of replacements performed
to the caller.

Fixes: #225
2021-02-09 10:50:16 +00:00
Philip Withnall
f8cf0b8672 gstrfuncs: Add g_memdup2() function
This will replace the existing `g_memdup()` function, which has an
unavoidable security flaw of taking its `byte_size` argument as a
`guint` rather than as a `gsize`. Most callers will expect it to be a
`gsize`, and may pass in large values which could silently be truncated,
resulting in an undersize allocation compared to what the caller
expects.

This could lead to a classic buffer overflow vulnerability for many
callers of `g_memdup()`.

`g_memdup2()`, in comparison, takes its `byte_size` as a `gsize`.

Spotted by Kevin Backhouse of GHSL.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: GHSL-2021-045
Helps: #2319
2021-02-04 14:13:03 +00:00
Xavier Claessens
4273c43902 glib_typeof: It is an API break that should be opt-in
That changes the return type of functions like g_object_ref() that can
break C++ applications like Webkit. Note that it is not an ABI break.

It must thus be opt-in the same way we did when adding this to
g_object_ref() for GNU C compilers in the first place. Unfortunately it
cannot be done directly in gmacros.h because GLIB_VERSION_2_68 is not
defined there, and gversionmacros.h cannot be included there because
there is some strict ordering in which those headers must be included.

This means that applications that does not define
GLIB_VERSION_MIN_REQUIRED will still get an API break, so we encourage
them to declare their minimum requirement to avoir such issues in the
future too.
2021-01-27 09:26:39 -05:00
Jonas Ådahl
657d18fdbb gtestutils: Add g_test_get_path() API
I found myself wanting to know the test that is currently being run,
where e.g. __func__ would be inconvenient to use, because e.g. the place
the string was needed was not in the test case function. Using __func__
also relies on the test function itself containing the whole path, while
loosing the "/" information that is part of the test path.
2021-01-25 16:34:12 +01:00