From e60bd6c6628e8ca7e8f2b464c155fa74527bcac9 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 9 Dec 2016 17:59:53 +0530 Subject: [PATCH] check: Don't check for malloc/realloc and try to fallback When malloc is not available, this will set #define malloc rpl_malloc which is implemented only inside libcheck, and not everything will link to libcheck. We don't really need to care too much about how malloc is implemented and we don't care about platforms that don't implement malloc. --- config.h.meson | 2 -- libs/gst/check/libcheck/Makefile.am | 23 ++------------- libs/gst/check/libcheck/README.txt | 6 ++++ libs/gst/check/libcheck/libcompat/malloc.c | 41 --------------------------- libs/gst/check/libcheck/libcompat/realloc.c | 44 ----------------------------- libs/gst/check/libcheck/meson.build | 12 ++------ m4/check-checks.m4 | 5 ---- 7 files changed, 10 insertions(+), 123 deletions(-) delete mode 100644 libs/gst/check/libcheck/libcompat/malloc.c delete mode 100644 libs/gst/check/libcheck/libcompat/realloc.c diff --git a/config.h.meson b/config.h.meson index d7e14e5..808586d 100644 --- a/config.h.meson +++ b/config.h.meson @@ -441,8 +441,6 @@ #mesondefine HAVE_UNWIND #mesondefine HAVE_DW #mesondefine HAVE_BACKTRACE -#mesondefine HAVE_MALLOC -#mesondefine HAVE_REALLOC #mesondefine HAVE_GETTIMEOFDAY #mesondefine HAVE_GETLINE #mesondefine STRUCT_TIMESPEC_DEFINITION_MISSING diff --git a/libs/gst/check/libcheck/Makefile.am b/libs/gst/check/libcheck/Makefile.am index f17dc56..4b90803 100644 --- a/libs/gst/check/libcheck/Makefile.am +++ b/libs/gst/check/libcheck/Makefile.am @@ -30,29 +30,10 @@ if !HAVE_LOCALTIME_R CFILES += libcompat/localtime_r.c endif -if !HAVE_MALLOC -CFILES += libcompat/malloc.c -endif - -if !HAVE_REALLOC -CFILES += libcompat/realloc.c -endif - if !HAVE_STRSIGNAL CFILES += libcompat/strsignal.c endif -# If either vsnprintf or snprintf is unavailable -# XXX: Commented out because none of our supported platforms need it yet and the -# check is a bit involved. No use slowing everyone down for this yet. -#if !HAVE_VSNPRINTF -#CFILES += libcompat/snprintf.c -#else -#if !HAVE_SNPRINTF -#CFILES += libcompat/snprintf.c -#endif -#endif - if !HAVE_STRDUP CFILES += libcompat/strdup.c endif @@ -95,5 +76,5 @@ libcheckinternal_la_CFLAGS += -D_GNU_SOURCE endif # Don't want libcompat to think we don't have these and substitute replacements -# See the commented-out vsnprintf/snprintf CFILES stuff above -libcheckinternal_la_CFLAGS += -DHAVE_SNPRINTF -DHAVE_VSNPRINTF +# See libcompat/libcompat.h +libcheckinternal_la_CFLAGS += -DHAVE_SNPRINTF -DHAVE_VSNPRINTF -DHAVE_MALLOC -DHAVE_REALLOC diff --git a/libs/gst/check/libcheck/README.txt b/libs/gst/check/libcheck/README.txt index 04f3bbb..cc0f2ed 100644 --- a/libs/gst/check/libcheck/README.txt +++ b/libs/gst/check/libcheck/README.txt @@ -11,6 +11,12 @@ those in the lib/ directory upstream. lib/snprintf.c was omitted since we don't run on any platforms that don't provide snprintf and the upstream implementation is ~2000 lines. +lib/malloc.c and lib/realloc.c were omitted since we were doing fine without +them and it does a #define malloc rpl_malloc on Android because the malloc +shipped with Bionic is not GNU-compliant. rpl_malloc is provided by libcheck, +but not everything in gstreamer links against libcheck. We also don't care +about this. + Steps to sync with upstream: 1. Clone libcheck from the above git repository diff --git a/libs/gst/check/libcheck/libcompat/malloc.c b/libs/gst/check/libcheck/libcompat/malloc.c deleted file mode 100644 index b70a1cd..0000000 --- a/libs/gst/check/libcheck/libcompat/malloc.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Check: a unit test framework for C - * Copyright (C) 2001, 2002 Arien Malec - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -/* - * AC_FUNC_MALLOC in configure defines malloc to rpl_malloc if - * malloc (0) is NULL to provide GNU compatibility - */ - -#include "libcompat.h" - -/* malloc has been defined to rpl_malloc, so first undo that */ -#undef malloc - -/* this gives us the real malloc to use below */ -void *malloc (size_t n); - -/* force malloc(0) to return a valid pointer */ -void * -rpl_malloc (size_t n) -{ - if (n == 0) - n = 1; - return malloc (n); -} diff --git a/libs/gst/check/libcheck/libcompat/realloc.c b/libs/gst/check/libcheck/libcompat/realloc.c deleted file mode 100644 index 81303c3..0000000 --- a/libs/gst/check/libcheck/libcompat/realloc.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Check: a unit test framework for C - * Copyright (C) 2001, 2002 Arien Malec - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -/* - * AC_FUNC_REALLOC in configure defines realloc to rpl_realloc if - * realloc (p, 0) or realloc (0, n) is NULL to provide GNU - * compatibility - */ - -#include "libcompat.h" - -/* realloc has been defined to rpl_realloc, so first undo that */ -#undef realloc - -/* this gives us the real realloc to use below */ -void *realloc (void *p, size_t n); - -/* force realloc(p, 0) and realloc (NULL, n) to return a valid pointer */ -void * -rpl_realloc (void *p, size_t n) -{ - if (n == 0) - n = 1; - if (p == 0) - return malloc (n); - return realloc (p, n); -} diff --git a/libs/gst/check/libcheck/meson.build b/libs/gst/check/libcheck/meson.build index 47abadf..6130764 100644 --- a/libs/gst/check/libcheck/meson.build +++ b/libs/gst/check/libcheck/meson.build @@ -27,14 +27,6 @@ if not cdata.has('HAVE_DECL_LOCALTIME_R') libcheck_files += ['libcompat/localtime_r.c'] endif -if not cdata.has('HAVE_MALLOC') - libcheck_files += ['libcompat/malloc.c'] -endif - -if not cdata.has('HAVE_REALLOC') - libcheck_files += ['libcompat/realloc.c'] -endif - if not cdata.has('HAVE_DECL_STRSIGNAL') libcheck_files += ['libcompat/strsignal.c'] endif @@ -68,6 +60,6 @@ libcheck = static_library('check', dependencies : [rt_lib, mathlib], c_args: gst_c_args + # Don't want libcompat to think we don't have these and substitute - # replacements since we don't check for or define these. - ['-DHAVE_VSNPRINTF', '-DHAVE_SNPRINTF'], + # replacements since we don't check for or define these. See libcompat.h + ['-DHAVE_VSNPRINTF', '-DHAVE_SNPRINTF', '-DHAVE_MALLOC', '-DHAVE_REALLOC'], pic: true) diff --git a/m4/check-checks.m4 b/m4/check-checks.m4 index 0a2cb59..44baca4 100644 --- a/m4/check-checks.m4 +++ b/m4/check-checks.m4 @@ -18,11 +18,6 @@ AC_SUBST(CHECK_VERSION) dnl Checks for header files and declarations AC_CHECK_HEADERS([unistd.h sys/wait.h sys/time.h], [], [], [AC_INCLUDES_DEFAULT]) -AC_FUNC_MALLOC -AC_FUNC_REALLOC -AM_CONDITIONAL(HAVE_MALLOC, test "x$ac_cv_func_malloc" = "xyes") -AM_CONDITIONAL(HAVE_REALLOC, test "x$ac_cv_func_realloc" = "xyes") - dnl Check for localtime_r() AC_CHECK_FUNCS([localtime_r]) AM_CONDITIONAL(HAVE_LOCALTIME_R, test "x$ac_cv_func_localtime_r" = "xyes") -- 2.7.4