Add compatibility code for g_string_free_and_steal() in glib before 2.76.
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 11 May 2023 01:10:11 +0000 (18:10 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 11 May 2023 01:11:34 +0000 (18:11 -0700)
Thanks to Jeremy Lavergne for reporting this bug.
Bug #64178.

configure.ac
src/ui/gui/automake.mk
src/ui/gui/glibfix.h [deleted file]
src/ui/gui/include/glib.in.h [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-recode.c
src/ui/gui/psppire-format.c
src/ui/gui/psppire-val-chooser.c

index 84f355dd05429315411e7a85e492f15be42cd404..2af7cd4214a1ec86cd75630611d5d81d1f2d8bda 100644 (file)
@@ -158,6 +158,7 @@ if test "$with_gui" != "no"; then
 
 fi
 
+gl_NEXT_HEADERS([glib.h])
 gl_NEXT_HEADERS([gtk/gtk.h])
 
 dnl Checks needed for psql reader
index 5f0d3acad1664756b32b0230e525e675e85f1ecf..2eee1558cf3ac66124b826f16facfcaf3744caec 100644 (file)
@@ -159,7 +159,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/executor.h \
        src/ui/gui/find-dialog.c \
        src/ui/gui/find-dialog.h \
-       src/ui/gui/glibfix.h \
        src/ui/gui/goto-case-dialog.c \
        src/ui/gui/goto-case-dialog.h \
        src/ui/gui/helper.c \
@@ -394,6 +393,7 @@ src/ui/gui/resources.c: src/ui/gui/resources.xml
        cat $@,out >> $@,tmp
        $(RM) $@,out
        mv $@,tmp $@
+EXTRA_DIST += src/ui/gui/resources.xml
 
 src/ui/gui/psppire-marshal.c: src/ui/gui/marshaller-list
        $(AM_V_GEN)echo '#include <config.h>' > $@
@@ -428,7 +428,24 @@ src/ui/gui/include/gtk/gtk.h: src/ui/gui/include/gtk/gtk.in.h
        } > $@-t && \
        mv $@-t $@
 CLEANFILES += src/ui/gui/include/gtk/gtk.h
-EXTRA_DIST += src/ui/gui/include/gtk/gtk.in.h src/ui/gui/resources.xml
+EXTRA_DIST += src/ui/gui/include/gtk/gtk.in.h
+
+# <glib.h> wrapper
+src_ui_gui_psppire_CPPFLAGS += $(AM_CPPFLAGS) -Isrc/ui/gui/include
+BUILT_SOURCES += src/ui/gui/include/glib.h
+src/ui/gui/include/glib.h: src/ui/gui/include/glib.in.h
+       @$(MKDIR_P) src/ui/gui/include
+       $(AM_V_GEN)rm -f $@-t $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         $(SED) -e 's|%''INCLUDE_NEXT''%|$(INCLUDE_NEXT)|g' \
+             -e 's|%''PRAGMA_SYSTEM_HEADER''%|$(PRAGMA_SYSTEM_HEADER)|g' \
+             -e 's|%''PRAGMA_COLUMNS''%|$(PRAGMA_COLUMNS)|g' \
+             -e 's|%''NEXT_GLIB_H''%|$(NEXT_GLIB_H)|g' \
+             < $(srcdir)/src/ui/gui/include/glib.in.h; \
+       } > $@-t && \
+       mv $@-t $@
+CLEANFILES += src/ui/gui/include/glib.h
+EXTRA_DIST += src/ui/gui/include/glib.in.h
 
 include $(top_srcdir)/src/ui/gui/icons/automake.mk
 
diff --git a/src/ui/gui/glibfix.h b/src/ui/gui/glibfix.h
deleted file mode 100644 (file)
index 3cb1cf5..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2022 Free Software Foundation
-
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef __GLIBFIX_H__
-#define __GLIBFIX_H__
-
-#include <config.h>
-
-/* Workaround for g_memdup2 which is introduced in glib 2.67.3
-   for earlier versions of glib
-   Taken from:
-   https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1927
-*/
-
-#ifndef HAVE_G_MEMDUP2
-static inline gpointer
-g_memdup2 (gconstpointer mem,
-           gsize         byte_size)
-{
-  gpointer new_mem;
-
-  if (mem && byte_size != 0)
-    {
-      new_mem = g_malloc (byte_size);
-      memcpy (new_mem, mem, byte_size);
-    }
-  else
-    new_mem = NULL;
-
-  return new_mem;
-}
-#endif
-
-#endif
diff --git a/src/ui/gui/include/glib.in.h b/src/ui/gui/include/glib.in.h
new file mode 100644 (file)
index 0000000..b87cb97
--- /dev/null
@@ -0,0 +1,60 @@
+/* Wrapper for <glib.h>.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef PSPP_GLIB_H
+#define PSPP_GLIB_H
+
+#if __GNUC__ >= 3
+%PRAGMA_SYSTEM_HEADER%
+#endif
+%PRAGMA_COLUMNS%
+
+#%INCLUDE_NEXT% %NEXT_GLIB_H%
+
+/* Workaround for g_memdup2 which is introduced in glib 2.67.3
+   for earlier versions of glib
+   Taken from:
+   https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1927
+*/
+
+#ifndef HAVE_G_MEMDUP2
+static inline gpointer
+g_memdup2 (gconstpointer mem,
+           gsize         byte_size)
+{
+  gpointer new_mem;
+
+  if (mem && byte_size != 0)
+    {
+      new_mem = g_malloc (byte_size);
+      memcpy (new_mem, mem, byte_size);
+    }
+  else
+    new_mem = NULL;
+
+  return new_mem;
+}
+#endif
+
+#if !GLIB_CHECK_VERSION(2, 76, 0)
+static inline gchar *
+g_string_free_and_steal (GString *string)
+{
+  return g_string_free (string, FALSE);
+}
+#endif
+
+#endif /* PSPP_GLIB_H */
index 3b7165f5cb2c2f9256f34f254596a76bdf864a74..9598cb7052b19e798914e13caa9e79b927cbb68d 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "helper.h"
 #include <ui/syntax-gen.h>
-#include "ui/gui/glibfix.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
index 1dde74fb0085638260bb2e1cdf5e2559465192ad..71cd4ffda99b43c0bf14e59901e601eda1af2475 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <config.h>
 #include "ui/gui/psppire-format.h"
-#include "ui/gui/glibfix.h"
 
 static gpointer
 psppire_format_copy (gpointer boxed)
index 543fb3f246ab7a9160316763e1519a3aece260cf..95f193ec0d67b4faa822071dd27e9e98d8918cdc 100644 (file)
@@ -22,7 +22,6 @@
 #include "psppire-val-chooser.h"
 
 #include "libpspp/str.h"
-#include "ui/gui/glibfix.h"
 
 #include "ui/syntax-gen.h"