From 816383e9efd7e83c49202a6ac71079ac71b036fa Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 4 Mar 2021 22:58:05 +0000 Subject: [PATCH] Handle static inline GtkOrdering function The introspection scanner does not handle `static inline` functions: they are not in the shared library, so cannot be dlsym() out of it; and the `static` keyword tells g-ir-scanner to skip the function declaration entirely. We can trick the scanner into thinking the gtk_ordering_from_cmpfunc() symbol is a real, public one, by declaring and defining a regular function under the `__GI_SCANNER__` guard; the symbol does not appear when actually building GTK, or any code using GTK, so we don't risk collisions. --- gtk/gtkenums.h | 11 ++++++++++- gtk/gtksorter.c | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h index 775af29173..da20f7a87a 100644 --- a/gtk/gtkenums.h +++ b/gtk/gtkenums.h @@ -548,7 +548,7 @@ typedef enum * These values can be used with a `GCompareFunc`. However, * a `GCompareFunc` is allowed to return any integer values. * For converting such a value to a `GtkOrdering` value, use - * [func@Gtk.ordering_from_cmpfunc]. + * [func@Gtk.Ordering.from_cmpfunc]. */ typedef enum { GTK_ORDERING_SMALLER = -1, @@ -556,6 +556,14 @@ typedef enum { GTK_ORDERING_LARGER = 1 } GtkOrdering; +/* The GI scanner does not handle static inline functions, because + * of the `static` keyword; so we clip this out when parsing the + * header, and we replace it with a real function in gtksorter.c + * that only exists when parsing the source for introspection. + */ +#ifdef __GI_SCANNER__ +GtkOrdering gtk_ordering_from_cmpfunc (int cmpfunc_result); +#else /** * gtk_ordering_from_cmpfunc: * @cmpfunc_result: Result of a comparison function @@ -570,6 +578,7 @@ gtk_ordering_from_cmpfunc (int cmpfunc_result) { return (GtkOrdering) ((cmpfunc_result > 0) - (cmpfunc_result < 0)); } +#endif /** * GtkPageOrientation: diff --git a/gtk/gtksorter.c b/gtk/gtksorter.c index afd24c13f3..0ad3c2653b 100644 --- a/gtk/gtksorter.c +++ b/gtk/gtksorter.c @@ -364,3 +364,24 @@ gtk_sorter_changed_with_keys (GtkSorter *self, gtk_sorter_changed (self, change); } + +/* See the comment in gtkenums.h as to why we need to play + * games with the introspection scanner for static inline + * functions + */ +#ifdef __GI_SCANNER__ +/** + * gtk_ordering_from_cmpfunc: + * @cmpfunc_result: Result of a comparison function + * + * Converts the result of a `GCompareFunc` like strcmp() to a + * `GtkOrdering` value. + * + * Returns: the corresponding `GtkOrdering` + **/ +GtkOrdering +gtk_ordering_from_cmpfunc (int cmpfunc_result) +{ + return (GtkOrdering) ((cmpfunc_result > 0) - (cmpfunc_result < 0)); +} +#endif