summaryrefslogtreecommitdiff
path: root/docs/reference/glib
Commit message (Collapse)AuthorAgeFilesLines
...
| * docs: Fix references to omitted requirements in GVariant SpecificationPhilip Withnall2022-11-081-7/+7
| | | | | | | | | | | | | | | | | | | | | | 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>
| * docs: Add licensing/copyright data to GVariant specificationPhilip Withnall2022-11-085-10/+149
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Revert "meson: Define G_OS_DARWIN when compiling under OSX or iOS"Philip Withnall2022-11-072-6/+0
|/ | | | | | | | This reverts commit e85635daa07e9c669ded75c476d67d02aa85c7c1. See the previous revert for rationale. Fixes: #2802
* Apply 2 suggestion(s) to 1 file(s)Emmanuele Bassi2022-11-011-2/+2
|
* docs: Convert GVariant Specification to reStructuredTextPhilip Withnall2022-11-016-0/+2624
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* gstdio: Add g_clear_fd() and g_autofdSimon McVittie2022-10-261-0/+2
| | | | | | | | | | | | | | | | | 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>
* meson: Define G_OS_DARWIN when compiling under OSX or iOSMarco Trevisan (Treviño)2022-10-202-0/+6
| | | | It has enough differences to expose it as an unix-subtype.
* Merge branch 'wip/chergert/g_set_str' into 'main'Philip Withnall2022-10-151-0/+1
|\ | | | | | | | | | | | | strfuncs: add g_set_str() Closes #2747 See merge request GNOME/glib!2927
| * strfuncs: add g_set_str()Christian Hergert2022-10-141-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | gbookmarkfile: Add copy functionMarco Trevisan (Treviño)2022-10-141-0/+1
|/ | | | | | | | 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.
* docs: Add 2.76 release series documentation pages to the buildPhilip Withnall2022-10-141-0/+4
| | | | Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* Fix symbol visibility macros on WindowsXavier Claessens2022-10-132-335/+11
| | | | | | | | | | | | | | | | | | | | | 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.
* Improve default value of glib_debug optionMichael Catanzaro2022-08-031-8/+3
| | | | | | | | | | | | | | | | | | | | | | | 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.
* replace pcre1 with pcre2Aleksei Rybalkin2022-07-121-46/+0
|
* gmacros: Provide platform-independent G_ALWAYS_INLINE and G_NO_INLINEMarco Trevisan (Treviño)2022-07-061-0/+5
| | | | | | | | 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.
* gatomic: Add Compare and Exchange functions that returns the previous valueMarco Trevisan (Treviño)2022-06-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | 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; }
* meson: simplify iconv lookups using Meson's builtin dependency lookupEli Schwartz2022-06-161-11/+7
| | | | | | | | | | | | | | | | | | | 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.
* gatomic: Add APIs to perform atomic int / pointer exchangesMarco Trevisan (Treviño)2022-06-071-0/+2
| | | | | | | | | | | | | | | | 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.
* array: add support for %NULL termination in GPtrArrayThomas Haller2022-05-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add one-shot idle and timeout functionsEmmanuele Bassi2022-05-271-0/+3
| | | | | | | | | | | 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.
* Add g_datalist_id_remove_multipleMatthias Clasen2022-05-231-0/+1
| | | | | | | | | | | 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.
* gio: Add g_list_store_find_with_equal_func_full()Jason Francis2022-04-051-0/+1
| | | | Fixes: #2447
* gversionmacros: Add version macros for GLib 2.74Philip Withnall2022-03-282-0/+18
| | | | Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* Merge branch 'ebassi/aligned-alloc' into 'main'Philip Withnall2022-02-111-0/+5
|\ | | | | | | | | | | | | Add aligned memory allocators Closes #2574 See merge request GNOME/glib!2421
| * Add aligned memory allocatorsEmmanuele Bassi2022-02-111-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Merge branch '1190-debug-interface' into 'main'Philip Withnall2022-01-271-0/+2
|\ \ | | | | | | | | | | | | | | | | | | gdebugcontroller: Add debug controller API and D-Bus implementation Closes #1190 See merge request GNOME/glib!2330
| * | gmessages: Expose a property for enabling debug message outputPhilip Withnall2022-01-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | ghash: Add g_hash_table_new_similar()Jonas Ådahl2022-01-181-0/+1
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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; } ```
* | utils: Add XDG_STATE_HOME supportSophie Herold2021-12-241-0/+1
| |
* | docs: Improve GVariant docsMohammed Sadiq2021-11-291-2/+8
| | | | | | | | | | Fix a typo and expand examples to include freeing memory where it's not obvious
* | galloca: Add new API g_alloca0 and g_newa0Marc-André Lureau2021-11-261-0/+2
| | | | | | | | | | | | | | | | | | 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.
* | Better detection of the cleanup attribute.Alvarito0505062021-11-161-0/+1
|/ | | | | | | 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.
* Add g_main_context_new_with_flags()Vinícius dos Santos Oliveira2021-09-211-0/+2
| | | | | This constructor is useful to set options that can't change after creation.
* gversionmacros: Add version macros for GLib 2.72Philip Withnall2021-09-172-0/+18
| | | | Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* Fix false deprecation warnings on old GCC/MSVCEvan Miller2021-09-071-0/+1
| | | | Closes #2472
* gtestutils: Allow failing a test with a printf-style messageSimon McVittie2021-08-191-0/+1
| | | | | | | | | | | | | | | | 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>
* gtestutils: Allow skipping tests with a printf-style messageSimon McVittie2021-08-191-0/+2
| | | | | | | | | | | 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>
* Merge branch 'main' into 'main'Philip Withnall2021-07-261-0/+2
|\ | | | | | | | | Fix some test suite memory leaks See merge request GNOME/glib!2195
| * glib/gtestutils: Introduce and use a g_test_suite_free functionGOUJON Évan2021-07-231-0/+1
| |
| * glib/gtestutils: Introduce and use a g_test_case_free functionGOUJON Évan2021-07-231-0/+1
| |
* | mainloop: Add g_source_set_static_nameMatthias Clasen2021-07-241-0/+1
|/ | | | | | | | 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.
* API: Add g_module_open_full()nitinosiris2021-07-211-0/+5
| | | | | | | g_module_open_full() is wrapper around g_module_open() function which returns a GError in case of failure. Closes #203
* GThreadPool: Add g_thread_pool_new_full()nitinosiris2021-07-021-0/+1
| | | | | | | g_thread_pool_new_full() is similar to g_thread_pool_new() but with GDestroyNotify argument. Closes #121
* Merge branch 'wip/pwithnall/962-drop-embedded-pcre' into 'main'Philip Withnall2021-06-212-47/+3
|\ | | | | | | | | | | | | pcre: Drop internal libpcre copy Closes #962 and #642 See merge request GNOME/glib!2144
| * pcre: Drop internal libpcre copyPhilip Withnall2021-06-161-2/+0
| | | | | | | | | | | | | | | | It’s no longer used and is a maintenance burden. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #962
| * build: Drop the internal_pcre option in favour of the subprojectPhilip Withnall2021-06-161-45/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Distinguish more clearly between wait status and exit statusSimon McVittie2021-06-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | GBytes: add range-checked pointer getterNitin Wartkar2021-06-151-0/+1
| | | | | | | | | | | | Updated and improved by Nitin Wartkar. Fixes: #1098
* | Merge branch 'gtypeof' into 'main'Philip Withnall2021-06-101-1/+0
|\ \ | | | | | | | | | | | | glib_typeof: Move definition to its own header See merge request GNOME/glib!1969
| * | glib_typeof: Move definition to its own headerXavier Claessens2021-05-171-1/+0
| | | | | | | | | | | | | | | | | | 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.