From c0eddf46ed56dde9558408b9b06eb19f4ff7538a Mon Sep 17 00:00:00 2001 From: Friedrich Beckmann Date: Sun, 10 Jul 2022 22:33:24 +0200 Subject: [PATCH] supply g_memdup2() for glib before 2.68. 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 | 4 ++ src/ui/gui/glibfix.h | 47 +++++++++++++++++++++++ src/ui/gui/psppire-dialog-action-recode.c | 4 +- src/ui/gui/psppire-format.c | 3 +- src/ui/gui/psppire-val-chooser.c | 4 +- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/ui/gui/glibfix.h diff --git a/configure.ac b/configure.ac index b8e8b7ddce..7e2fedec0c 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000000..3cb1cf5735 --- /dev/null +++ b/src/ui/gui/glibfix.h @@ -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 . */ + +#ifndef __GLIBFIX_H__ +#define __GLIBFIX_H__ + +#include + +/* 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/psppire-dialog-action-recode.c b/src/ui/gui/psppire-dialog-action-recode.c index 0087e4403e..3b7165f5cb 100644 --- a/src/ui/gui/psppire-dialog-action-recode.c +++ b/src/ui/gui/psppire-dialog-action-recode.c @@ -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 @@ -31,12 +31,12 @@ #include "helper.h" #include +#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? */ diff --git a/src/ui/gui/psppire-format.c b/src/ui/gui/psppire-format.c index 392ac73b2d..1dde74fb00 100644 --- a/src/ui/gui/psppire-format.c +++ b/src/ui/gui/psppire-format.c @@ -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 #include "ui/gui/psppire-format.h" +#include "ui/gui/glibfix.h" static gpointer psppire_format_copy (gpointer boxed) diff --git a/src/ui/gui/psppire-val-chooser.c b/src/ui/gui/psppire-val-chooser.c index f3f5624732..543fb3f246 100644 --- a/src/ui/gui/psppire-val-chooser.c +++ b/src/ui/gui/psppire-val-chooser.c @@ -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" -- 2.30.2