supply g_memdup2() for glib before 2.68.
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 10 Jul 2022 20:33:24 +0000 (22:33 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 10 Jul 2022 20:33:24 +0000 (22:33 +0200)
The previous commit did not work on debian. I followed the ideas from

https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1927

and

https://github.com/mdbtools/gmdb2/commit/62ce520a9c5

So this commit provides g_memdup2 for glib versions which do not
provide g_memdup2.

configure.ac
src/ui/gui/glibfix.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 b8e8b7ddce58d89d4cef4480ac643a45daefeae5..7e2fedec0c45bc15cc82be51db5d6373d1a97fe6 100644 (file)
@@ -152,6 +152,10 @@ if test "$with_gui" != "no"; then
     PSPP_REQUIRED_PREREQ([glib-compile-resources (or use --without-gui)])
   fi
 
+  dnl g_memdup2 has been introduced in glib 2.67.3. Older versions need
+  dnl a workaround
+  AC_CHECK_LIB(glib-2.0, g_memdup2, [AC_DEFINE([HAVE_G_MEMDUP2], [1], [g_memdup2 check])])
+
 fi
 
 gl_NEXT_HEADERS([gtk/gtk.h])
diff --git a/src/ui/gui/glibfix.h b/src/ui/gui/glibfix.h
new file mode 100644 (file)
index 0000000..3cb1cf5
--- /dev/null
@@ -0,0 +1,47 @@
+/* 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
index 0087e4403e8b14a62aae8a7feff8abb7c91c76f2..3b7165f5cb2c2f9256f34f254596a76bdf864a74 100644 (file)
@@ -1,6 +1,6 @@
 /* PSPPIRE - a graphical user interface for PSPP.
    Copyright (C) 2007, 2009, 2010, 2011, 2012, 2014, 2016,
-   2020  Free Software Foundation
+   2020, 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
 
 #include "helper.h"
 #include <ui/syntax-gen.h>
+#include "ui/gui/glibfix.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
-
 /* This might need to be changed to something less naive.
    In particular, what happends with dates, etc?
  */
index 392ac73b2d19e2440817464207f2c82a42676573..1dde74fb0085638260bb2e1cdf5e2559465192ad 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2012 Free Software Foundation
+   Copyright (C) 2012, 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
@@ -16,6 +16,7 @@
 
 #include <config.h>
 #include "ui/gui/psppire-format.h"
+#include "ui/gui/glibfix.h"
 
 static gpointer
 psppire_format_copy (gpointer boxed)
index f3f56247321aa04512cd2b42a0c542dd44c64edb..543fb3f246ab7a9160316763e1519a3aece260cf 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2011, 2014  Free Software Foundation
+   Copyright (C) 2011, 2014, 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
@@ -22,7 +22,7 @@
 #include "psppire-val-chooser.h"
 
 #include "libpspp/str.h"
-
+#include "ui/gui/glibfix.h"
 
 #include "ui/syntax-gen.h"