summaryrefslogtreecommitdiff
path: root/glib/gmacros.h
Commit message (Collapse)AuthorAgeFilesLines
* gmacros: Document soft-deprecation of G_GNUC_NORETURNPhilip Withnall2020-11-251-0/+6
| | | | | | | | | | It still works, and deprecating it would be quite disruptive (as it’s used in headers), so amend the documentation to point people to `G_NORETURN` instead. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #994
* Adding macros G_NORETURN and G_NORETURN_FUNCPTREmmanuel Fleury2020-11-251-0/+70
| | | | | | This macro is borrowed from the gnulib project in the 'noreturn.h' file. Fixes: #994
* gmacros: Use __typeof__ when compiling with ClangPhilip Withnall2020-10-231-1/+3
| | | | | | | | | | | | | | Just like gcc, clang has supported `__typeof__` for a long time, so allow it to be used. This fixes compilation of `gio/gcredentials.c` on macOS (which uses clang by default). I don’t know which version clang started supporting `__typeof__` in, so there’s no version check. One can be added in future if there are problems. This fixes commit 5b2bee3f539. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
* Revert "Use C++11 decltype where possible"Philip Withnall2020-10-211-4/+0
| | | | | | | | | This reverts commit 0d81443ec025b832d3f072a25bdc8e74c13a3919. It breaks WebKit and GJS, so should be reverted for now. These changes may be reintroduced if a solution can be found for the breakage. See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1575#note_940048
* Use C++11 decltype where possibleXavier Claessens2020-10-141-0/+4
| | | | | | | | | | | | There are various places glib uses __typeof__ for type safety, but that's a GNUC extension. C++11 has standard decltype() that does a similar job, at least for cases we care about. This avoids C++ code to always have to cast return value of g_object_ref() which was causing type kind of error: error: invalid conversion from ‘gpointer’ {aka ‘void*’} to ‘GstElementFactory*’ {aka ‘_GstElementFactory*’} [-fpermissive]
* Replace __typeof__ with glib_typeof macroXavier Claessens2020-10-141-2/+2
| | | | | | | g_has_typeof macro is wrongly in the public g_ namespace, internaly symbols are usually in the glib_ namespace. This will also allow to define glib_typeof differently on non-GNUC compilers (e.g. c++11 decltype).
* tree: Fix various typos and outdated terminologyPhilip Withnall2020-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This was mostly machine generated with the following command: ``` codespell \ --builtin clear,rare,usage \ --skip './po/*' --skip './.git/*' --skip './NEWS*' \ --write-changes . ``` using the latest git version of `codespell` as per [these instructions](https://github.com/codespell-project/codespell#user-content-updating). Then I manually checked each change using `git add -p`, made a few manual fixups and dropped a load of incorrect changes. There are still some outdated or loaded terms used in GLib, mostly to do with git branch terminology. They will need to be changed later as part of a wider migration of git terminology. If I’ve missed anything, please file an issue! Signed-off-by: Philip Withnall <withnall@endlessm.com>
* gmacros: Add missing GLIB_UNAVAILABLE_STATIC_INLINE declarationPhilip Withnall2020-05-151-0/+1
| | | | | | | | This fixes building against GLib with `GLIB_DISABLE_DEPRECATION_WARNINGS` defined. Signed-off-by: Philip Withnall <withnall@endlessm.com> See: !1487
* Revert "Revert "glib: annotate static inline functions with G_AVAILABLE-type ↵Philip Withnall2020-05-151-0/+1
| | | | | | | | | | | | macros"" This reverts commit c0146be3a4e0cda7a23d7fd54cc60a0bc7ba7f7a. The revert was originally added because the original change broke gnome-build-meta. Now that the problem has been diagnosed, the original commit can be fixed — see the commit which follows this one. See: !1487
* Revert "glib: annotate static inline functions with G_AVAILABLE-type macros"Michael Catanzaro2020-05-121-1/+0
| | | This reverts commit 50502987495ad55b5168e23b0c0283924881a8b3
* glib: annotate static inline functions with G_AVAILABLE-type macrosSimon Marchi2020-05-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The public functions exposed as static inlines currently don't have annotations to describe when they were introduced. This means that compiling this file: #include <glib.h> void foo (void) { g_rec_mutex_locker_new (NULL); } with: gcc -c test.c \ -I/tmp/glib/include/glib-2.0 \ -I/tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \ -Werror \ -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 \ -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28 will not produce any error message, despite using `g_rec_mutex_locker_new`, a function that was introduced after 2.28. This patch adds some annotations to all the publicly exposed static inline functions I could find. I could not use the existing G_AVAILABLE* macros, because they may expand to `extern`. This would then clash with the `static` keyword and produce: ../glib/gthread.h:397:1: error: multiple storage classes in declaration specifiers 397 | static inline GRecMutexLocker * | ^~~~~~ So I opted for adding a new set of macros, GLIB_AVAILABLE_STATIC_INLINE_IN_2_XY. With this patch applied, the example from above produces the expected warning: test.c: In function ‘foo’: test.c:5:3: error: ‘g_rec_mutex_locker_new’ is deprecated: Not available before 2.60 [-Werror=deprecated-declarations] 5 | g_rec_mutex_locker_new (NULL); | ^~~~~~~~~~~~~~~~~~~~~~ In file included from /tmp/glib/include/glib-2.0/glib/gasyncqueue.h:32, from /tmp/glib/include/glib-2.0/glib.h:32, from test.c:1: /tmp/glib/include/glib-2.0/glib/gthread.h:398:1: note: declared here 398 | g_rec_mutex_locker_new (GRecMutex *rec_mutex) | ^~~~~~~~~~~~~~~~~~~~~~
* gmacros.h: avoid using _Static_assert in C++17 modeAlexander Pyhalov2020-03-171-1/+1
| | | | Closes #2067
* macros: Define G_GNUC_FALLTHROUGH for more compilersTimm Bäder2020-02-281-1/+3
| | | | | | Some compilers have __GNUC__ defined as a value less than 6, but do support implicit-fallthrough via __attribute__((fallthrough)). Define G_GNUC_FALLTHROUGH for those that support __has_attribute.
* doc: Fix undocumented G_SIZEOF_MEMBERXavier Claessens2020-01-291-1/+3
| | | | A body in the documentation comment is required.
* Add and use G_SIZEOF_MEMBER() macroMarc-André Lureau2020-01-211-0/+14
| | | | | | A convenient macro present in the Linux kernel, named FIELD_SIZE() there. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* Improve GLIB_DEPRECATED_MACRO_FOR outputStephan Bergmann2019-09-261-1/+1
| | | | | | | | | | | | | | | | | | | See the mailing list thread <https://lists.fedoraproject.org/archives/list/ devel@lists.fedoraproject.org/thread/SZ676IHHSLOQD6UN2I5J5VKXJ5P5SOVO/> "glib-2.0 G_CONST_RETURN causing GCC 'warning: const' on F31", where the GCC diagnostic > test.c:2:13: warning: const > 2 | G_CONST_RETURN char * f(); > | ^~~~~~~ had confused me, and "Deprecated pre-processor symbol, repace with const" is probably a better warning message than just "const". (That recent GCC only prints "Deprecated pre-processor symbol, repace with " appears to be a bug in GCC that GLIB_UNAVAILABLE_MACRO already suffers from, too. Recent Clang correctly prints "Deprecated pre-processor symbol, repace with const".)
* gmacros: mark functions generated by autoptr macros as unusedMatthew Waters2019-08-281-2/+2
| | | | | | | | | clang will warn with -Wunused-function if the g_autoptr macros are ever used inside a .c file. This would break a lot of -Werror builds with clang. Mark such functions as explicitly unsed so clang will not warn about them.
* gmacros.h: Support deprecation macros better on clang-clChun-wei Fan2019-07-101-6/+6
| | | | | | | | Use the GCC-style definition for the deprecation warning macros so that builds using those won't break due to how they are placed as clang-cl seems to not support __declspec(deprecated) very well. Also make sure that we do indeed support the temparary disabling of deprecation warnings on clang-cl, as the MSVC ones don't really work on clang-cl.
* glib/gmacros.h: Check for __clang__ for g_autoptrChun-wei Fan2019-07-101-1/+1
| | | | | | | | | | | clang-cl does support __attribute__((cleanup)), which is what is used for the g_auto* macros, but neither it, nor clang.exe defines __GNUC__ when they are used in a MSVC cmd.exe environment. It does, however, define __clang__. So, check for the presence of the __clang__ macro to enable g_autoptr as well, so that we can build things with MSVC builds that make use of g_autoptr via pretending to be MSVC by using clang-cl.
* gmacros.h: Use static_assert on MSVC if possibleChun-wei Fan2019-07-021-1/+3
| | | | | | | | | Visual Studio 2010 and later support static_assert on both C and C++, but we can only enable it for plain-C code on Visual Studio 2013 and later, as apparently the static_assert macro implementation will carry out something after defining certain variables. For C++ code, we use static_assert on Visual Studio 2010 and later.
* gmacros: Use _Static_assert only for non-expr static assertNirbheek Chauhan2019-07-011-1/+7
| | | | | | | | We can't actually use it inside an expression, so keep the old macro for that. Also add a test so that this doesn't break the next time we change it. See: https://gitlab.gnome.org/GNOME/glib/merge_requests/955#note_542646
* Revert "gmacros: Use _Static_assert when C11 is available"Michael Catanzaro2019-06-291-9/+1
| | | | | | This reverts commit 5d14764a6bcfc970e740a3d83b4a9eb06de5077e. It broke G_STATIC_ASSERT_EXPR(). See discussion in !955.
* gmacros: Use _Static_assert when C11 is availableNirbheek Chauhan2019-06-271-1/+9
| | | | | | | | The static assert message is much nicer to read, and is less likely to be misinterpreted as a false positive. glib is built with `-std=gnu89`, but this macro will be available to projects that use glib with c11 or gnu11.
* Check if compiler symbols are defined before using themEmmanuele Bassi2019-06-171-4/+4
| | | | If we don't do this, projects using `-Werror=undef` will break.
* gmacros: Only use deprecated attributes on enumerators with GCC ≥ 6.1Philip Withnall2019-06-141-1/+1
| | | | | | | | | | The reference I found online which said they were supported by GCC ≥ 5.2 was obviously lying. The GCC 6.1.0 documentation says they’re supported: https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/Enumerator-Attributes.html. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* glib, gio: Use GLIB_DEPRECATED_MACRO instead of G_DISABLE_DEPRECATEDPhilip Withnall2019-05-301-16/+11
| | | | | | | | | | | | | | When defining deprecated macros, annotate them with `GLIB_DEPRECATED_MACRO_IN_*()` and `GLIB_DEPRECATED_MACRO_IN_*_FOR()` to conditionally emit warnings if people use them, depending on their declared minimum and maximum GLib version requirements (see `GLIB_VERSION_MIN_REQUIRED` and `GLIB_VERSION_MAX_ALLOWED`). The old way of doing this was for users to define `G_DISABLE_DEPRECATED` if they didn’t want to use deprecated APIs, but it reported errors via missing symbols, and wasn’t version-dependent. It’s being phased out. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* gmacros: Add GLIB_DEPRECATED_{MACRO,ENUMERATOR,TYPE}{,_FOR}Philip Withnall2019-05-301-1/+38
| | | | | | | | | | | | | | | These will be used to annotate deprecated macros, types and enumerators. `GLIB_DEPRECATED_MACRO{,_FOR}` are based very heavily on the corresponding macros from Clutter, written by Emmanuele Bassi. The other deprecation annotators use the standard annotations supported by Clang and GCC. They need to be separated as they are supported in different versions of the compilers. Signed-off-by: Philip Withnall <withnall@endlessm.com> Fixes: #1060
* glib: Move some documentation comments to where the symbols are definedPhilip Withnall2019-05-301-0/+34
| | | | | | | This makes it easier to maintain the documentation and code at the same time. The documentation comments haven’t been modified. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* gmacros: Add g_autoqueue to automatically free queuesMarco Trevisan (Treviño)2019-05-081-0/+6
| | | | | This works as g_auto(s)list already does, and allows to create queues that are fully auto free'd on destruction.
* Revert "macros: Try to use the standard __func__ first in G_STRFUNC"Philip Withnall2019-04-261-3/+3
| | | | | | | | | | | | | This reverts commit 9f75cc9edf1d311ef4bacc3d686c7afa0c4dcbb2. It breaks usage of G_STRFUNC when compiling applications with `-Wpedantic` — `__func__` is not `#define`d, so G_STRFUNC was falling through to using `__FUNCTION__`, which raises a warning with `-Wpedantic`. Fun times. Fixes: #1755
* Revert "headers: Add various missing G_DISABLE_DEPRECATED guards"Emmanuele Bassi2019-03-161-2/+2
| | | | | | | | | | | | | | | | | This reverts commit 80fcb1bc26edca17a996ee293153f8e07cfc9198. G_DISABLE_DEPRECATED should never be used by anybody, least of all by GLib. We have deprecation annotations for the compiler, these days, and they are much better suited than a macro that makes symbols appear and disappear. The fact that gtk-doc doesn't understand the deprecation annotations is a limitation of gtk-doc, and it's gtk-doc that ought to be fixed. Commit 80fcb1bc broke GStreamer, which disables old API that was deprecated before the introduction of the deprecation annotations, but still uses newly deprecated one, and relies on the deprecation annotations to do their thing. It also broke libsoup, as it uses GValueArray in its own API.
* docs: Move some documentation comments from docs.c to their symbolsPhilip Withnall2019-03-151-0/+30
| | | | | | | | | | | | | It would be nice if docs.c eventually went away — it’s more maintainable for documentation comments to be next to the definition of the symbols they document. Move a few from docs.c, based on what I’ve been modifying recently. The documentation comments are unchanged apart from fixing an argument name for G_ALIGNOF. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* headers: Add various missing G_DISABLE_DEPRECATED guardsPhilip Withnall2019-03-151-0/+2
| | | | | | | | | | | | As pointed out by gtk-doc, these are all symbols which have been marked as deprecated, but which aren’t protected by a deprecation guard. We can’t use G_DEPRECATED_IN_* for them, as they are all non-function symbols. Instead, wrap them in #ifndef G_DISABLE_DEPRECATED. In some cases, we also need to wrap one or two functions which use the deprecated types in G_DISABLE_DEPRECATED too. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* Provide examples for GNUC attribute macrosSimon McVittie2019-03-131-2/+86
| | | | | | | | It isn't always obvious how and where to use these. Where possible I've chosen real examples from GLib, preferring simple examples that developers considering using these macros have hopefully already seen. Signed-off-by: Simon McVittie <smcv@collabora.com>
* gmacros: Improve documentation of GCC attributesPhilip Withnall2019-03-081-46/+46
| | | | | | | Link to the GCC documentation pages, and format the attribute names as code. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* glib: Move various documentation comments from docs.c to macros.hPhilip Withnall2019-03-081-0/+329
| | | | | | | | | Move them next to their definitions, so they’re more likely to be kept up to date. This doesn’t modify any of the documentation comments at all. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* macros: Try to use the standard __func__ first in G_STRFUNCJavier Jardón2019-02-051-3/+3
| | | | | | | | | | | | | | __func__ is part of the C99 standard. __FUNCTION__ is another name for __func__. Older versions of GCC recognize only this name. However, it is not standardized. For maximum portability, Its recommended to use __func__. __PRETTY_FUNCTION__ is yet another name for __func__. However, in C++, __PRETTY_FUNCTION__ contains the type signature of the function as well as its bare name http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html https://gitlab.gnome.org/GNOME/glib/issues/535
* gmacros: MSVC supports the noreturn function attributeNirbheek Chauhan2019-01-151-0/+4
| | | | | | | | But it can't be used as a drop-in implementation of G_GNUC_NORETURN because it can only be placed at the start of the function prototype. Document this in a comment so that the next person doesn't spend 20 min figuring it out.
* gmacros: Don’t use __alignof__ in G_ALIGNOF implementationPhilip Withnall2018-12-211-2/+4
| | | | | | | | | It has different semantics from _Alignof and our G_STRUCT_OFFSET fallback. See the comments in the diff for details. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/glib/issues/1055
* gmacros: Add G_ALIGNOF superseding _g_alignof macroTapasweni Pathak2018-12-181-0/+11
|
* gmacros: remove duplication on autoptr cleanup definitionMarco Trevisan (Treviño)2018-11-141-19/+17
| | | | | Define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS and reuse it for both _GLIB_DEFINE_AUTOPTR_CHAINUP and G_DEFINE_AUTOPTR_CLEANUP_FUNC
* gmacros: make _GLIB_DEFINE_AUTOPTR_CHAINUP to define funcs for g_autolistMarco Trevisan (Treviño)2018-11-141-3/+11
| | | | | Also chainup to glib_(s)listautoptr_cleanup_* parent functions to make g_autolist work with object defined in this way
* Merge branch 'wip/sadiq/likely' into 'master'Philip Withnall2018-11-021-2/+2
|\ | | | | | | | | gmacros: Fix G_[UN]LIKELY to not mask -Wparentheses See merge request GNOME/glib!372
| * gmacros: Fix G_[UN]LIKELY to not mask -WparenthesesMohammed Sadiq2018-10-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | A double paren forces the compiler to assume that the statement is right. That may not be the case. This is essentially reverting b44fba25fbad89c105795a10a569fe422e4d1c44. See https://bugzilla.gnome.org/show_bug.cgi?id=760215. It's more morth to allow find common mistakes (= instead of == in conditionals) than masking them to make some rarely used code work.
* | gmacros: Add G_GNUC_STRFTIME macroChristian Persch2018-10-311-0/+5
|/ | | | | | | Analogous to G_GNUC_PRINTF and G_GNUC_SCANF, to annotate functions similar to strftime. https://gitlab.gnome.org/GNOME/glib/issues/1575
* macros: Add G_GNUC_FALLTHROUGHBenjamin Otte2018-09-041-0/+6
| | | | | | | Expands to the GNU C fallthrough statement attribute if the compiler is gcc. This allows declaring case statement to explicitly fall through in switch statements. To enable this feature, use -Wimplicit-fallthrough during compilation.
* gmacros: Add new private g_has_typeof to abstract __typeof__ checksIain Lane2018-07-161-0/+12
| | | | | | | We have this same check in a few places now, and we might as well abstract it out. Fixes #1440.
* Add a macro for checking approximate valuesEmmanuele Bassi2018-05-291-0/+3
| | | | | | | A macro like this is useful to avoid direct comparisons between floating point values. https://gitlab.gnome.org/GNOME/glib/issues/914
* macros: Double-cast func for g_autolist to avoid warningJan Alexander Steffens (heftig)2018-05-251-2/+2
| | | | | | | | | | | | | | For g_autolist and g_autoslist, the cleanup func was cast to GDestroyNotify before being passed to g_(s)list_free_full. This cast provokes GCC 8 to emit a warning if the return type is not void: …/gmacros.h:462:99: warning: cast between incompatible function types from … to 'void (*)(void *)' [-Wcast-function-type] Cast to 'void (*)(void)' first, which suppresses the warning as recommended by the GCC documentation. g_autoptr remains untouched. Fixes https://gitlab.gnome.org/GNOME/glib/issues/1382
* gmacros: Add G_GNUC_UNUSED for autoptr funcs (notably GLists)Colin Walters2018-05-251-3/+3
| | | | | | | | | | | | | | | In commit f49a93b20761a0be51b22c481503b4cda0f7264f from bug https://bugzilla.gnome.org/show_bug.cgi?id=791342 we added two new static inline cleanup helpers in case a type was used inside a list. These functions will commonly be unused. In rpm-ostree, we run a build using `CC=clang -Werror=unused` because it catches `g_autofree char *foo = NULL;` as unused, but GCC doesn't. When trying to update to F28 with a newer glib, our CI fell over on this. Mark all of the autocleanups as "maybe unused".