Bug#992246: gxtuner FTBFS with glib 2.68.3

2021-08-16 Thread Simon McVittie
On Mon, 16 Aug 2021 at 19:14:58 +0100, Simon McVittie wrote:
> 1. Move inclusions of system headers outside extern "C" blocks ...
>Attached patch 0001-Move-system-header-inclusions-outside-extern-C.patch
>implements this.
> 
> 2. Target a specific GLib version by defining the macros
>GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED ...
>Attached patch 0001-build-Target-a-specific-GLib-API-version.patch
>implements this.

Now with patches actually attached.

smcv
>From 26f06c0416b1266b7d70ade61a8d29050960a208 Mon Sep 17 00:00:00 2001
From: Simon McVittie 
Date: Mon, 16 Aug 2021 18:41:25 +0100
Subject: [PATCH] build: Target a specific GLib API version

Setting GLIB_VERSION_MIN_REQUIRED selects the minimum required version
of GLib for this project. Code that was deprecated after that version
will not cause deprecation warnings, and where header files have changed
their compile-time behaviour over time, the behaviour that was seen in
the selected version will be used where possible.

Setting GLIB_VERSION_MAX_ALLOWED causes GLib to emit warnings if a
function introduced after the selected version is used.

In particular, this disables new C++ behaviour introduced in GLib 2.68,
which caused this project to fail to build.

GLib 2.54 is an arbitrary choice: it happens to be the version that was
the current stable release when gxtuner 3.0.0 was released. It could
be reduced if gxtuner needs to compile on older distributions, or
increased if a newer dependency is acceptable.

Bug: https://github.com/brummer10/gxtuner/issues/19
Bug-Debian: https://bugs.debian.org/992246
Forwarded: https://github.com/brummer10/gxtuner/pull/21
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Makefile b/Makefile
index 88221f6..2680f86 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,8 @@
 	NAME = gxtuner
 	LIBS = `pkg-config --libs jack gtk+-3.0 gthread-2.0 fftw3f x11` -lzita-resampler
 	CFLAGS += -Wall -ffast-math `pkg-config --cflags jack gtk+-3.0 gthread-2.0 fftw3f`
+	CFLAGS += -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_54
+	CFLAGS += -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_54
 	OBJS = resources.o jacktuner.o gxtuner.o cmdparser.o gx_pitch_tracker.o gtkknob.o \
paintbox.o tuner.o deskpager.o main.o
 	DEBNAME = $(NAME)_$(VER)
-- 
2.32.0

>From 2f3771ed5a6ca17688280953eff2859ba93ba8d9 Mon Sep 17 00:00:00 2001
From: Simon McVittie 
Date: Mon, 16 Aug 2021 18:07:17 +0100
Subject: [PATCH] Move system header inclusions outside extern "C"

GLib and GTK both include extern "C" guards in their header files, so it
is unnecessary to wrap them in an extern "C" block.

A redundant extern "C" block can be harmful, because header files might
test #ifdef __cplusplus and include C++ syntax if it is defined, even in
an otherwise C header. In particular, GLib has done this since version
2.68, in order to make macros like g_object_ref() type-safe when called
from C++ code. the result was that this project failed to compile.

Bug: https://github.com/brummer10/gxtuner/issues/19
Bug-Debian: https://bugs.debian.org/992246
Forwarded: https://github.com/brummer10/gxtuner/pull/20
---
 gtkknob.h  | 4 ++--
 gxtuner.h  | 8 +++-
 paintbox.h | 4 ++--
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/gtkknob.h b/gtkknob.h
index d7d1cae..f5d8f0a 100644
--- a/gtkknob.h
+++ b/gtkknob.h
@@ -24,14 +24,14 @@
 #ifndef __GTK_KNOB_H__
 #define __GTK_KNOB_H__
 
+#include 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #pragma once
 
-#include 
-
 G_BEGIN_DECLS
 
 #define GTK_TYPE_KNOB  (gtk_knob_get_type())
diff --git a/gxtuner.h b/gxtuner.h
index 4b729ec..8ca2399 100644
--- a/gxtuner.h
+++ b/gxtuner.h
@@ -26,15 +26,13 @@
 #ifndef _GX_TUNER_H_
 #define _GX_TUNER_H_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include 
 #include 
 #include  
 
-
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 G_BEGIN_DECLS
 
diff --git a/paintbox.h b/paintbox.h
index 5e2781b..9821ef3 100644
--- a/paintbox.h
+++ b/paintbox.h
@@ -21,12 +21,12 @@
 #ifndef __PAINT_BOX_H__
 #define __PAINT_BOX_H__
 
+#include 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include 
-
 G_BEGIN_DECLS
 
 #define GX_TYPE_PAINT_BOX(gx_paint_box_get_type ())
-- 
2.32.0



Bug#992246: gxtuner FTBFS with glib 2.68.3

2021-08-16 Thread Simon McVittie
Control: tags -1 + patch
Control: forwarded -1 https://github.com/brummer10/gxtuner/issues/19

(Adrian: I don't intend to cc you on responses to all bugs of this class,
but I thought I'd cc you on the first one so that you can see what I'm
recommending as a solution.)

On Mon, 16 Aug 2021 at 13:33:01 +0300, Adrian Bunk wrote:
> In file included from /usr/include/glib-2.0/glib/gatomic.h:31,
>  from /usr/include/glib-2.0/glib/gthread.h:32,
>  from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
>  from /usr/include/glib-2.0/glib.h:32,
>  from /usr/include/glib-2.0/gobject/gbinding.h:28,
>  from /usr/include/glib-2.0/glib-object.h:22,
>  from ./gxtuner.h:33,
>  from gxtuner.cpp:24:
> /usr/include/c++/10/type_traits:56:3: error: template with C linkage
>56 |   template
>   |   ^~~~
> In file included from gxtuner.cpp:24:
> ./gxtuner.h:30:1: note: ‘extern "C"’ linkage started here
>30 | extern "C" {
>   | ^~

Bugs with this compiler error are caused by a header behaviour change
in GLib 2.68.

In older versions, the GLib headers contained only C code, even when
compiled with a C++ compiler. In GLib 2.68+, if C++ compilation is
detected, the headers make use of C++ features to make macros like
g_object_ref() more type-safe.

There are two ways to resolve the build failure:

1. Move inclusions of system headers outside extern "C" blocks, at least
   for well-behaved libraries like GLib and GTK that already include their
   own extern "C" guard, either directly or via macros like GLib's own
   G_BEGIN_DECLS/G_END_DECLS.

   Attached patch 0001-Move-system-header-inclusions-outside-extern-C.patch
   implements this. I've proposed it upstream.

2. Target a specific GLib version by defining the macros
   GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED (see GLib's
   documentation for details). This asks GLib to disable behaviour changes
   and deprecation warnings that happened since the target version.

   Attached patch 0001-build-Target-a-specific-GLib-API-version.patch
   implements this. I've proposed it upstream. The choice of GLib 2.54
   is completely arbitrary (it's the version that was current at the time
   gxtuner was most recently released) so an upstream or downstream
   maintainer could probably make a better choice.

Maintainers can choose either or both of those methods. I would personally
recommend doing both.

I've successfully compiled gxtuner against GLib 2.68.3 with each of those
patches, individually. I have not otherwise tested the resulting executables.

Thanks,
smcv



Bug#992246: gxtuner FTBFS with glib 2.68.3

2021-08-16 Thread Adrian Bunk
Source: gxtuner
Version: 3.0-2
Severity: serious
Tags: ftbfs bookworm sid

https://buildd.debian.org/status/package.php?p=gxtuner=sid

...
In file included from /usr/include/glib-2.0/glib/gatomic.h:31,
 from /usr/include/glib-2.0/glib/gthread.h:32,
 from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
 from /usr/include/glib-2.0/glib.h:32,
 from /usr/include/glib-2.0/gobject/gbinding.h:28,
 from /usr/include/glib-2.0/glib-object.h:22,
 from ./gxtuner.h:33,
 from gxtuner.cpp:24:
/usr/include/c++/10/type_traits:56:3: error: template with C linkage
   56 |   template
  |   ^~~~
In file included from gxtuner.cpp:24:
./gxtuner.h:30:1: note: ‘extern "C"’ linkage started here
   30 | extern "C" {
  | ^~
...