From d8e8e92176bb7a88961ca125081b46ab59a59b19 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 9 Dec 2016 15:18:11 +0530 Subject: [PATCH] libcheck: Update the compatibility code and checks This brings us up-to-speed with the latest compatibility code from upstream check git. For completeness, we do all the checks that upstream check does, but we skip the snprintf/vsnprintf code because it's not straightforward (involves running code and that is bad for cross-compilation) and not necessary for the platforms we support anyway. If someone really wants this, they can uncomment this and copy the relevant checks from the check git repository. https://bugzilla.gnome.org/show_bug.cgi?id=775870 --- config.h.meson | 8 +++ libs/gst/check/libcheck/Makefile.am | 39 +++++++++++++++ libs/gst/check/libcheck/libcompat/alarm.c | 20 ++++++++ libs/gst/check/libcheck/libcompat/clock_gettime.c | 21 ++++++++ libs/gst/check/libcheck/libcompat/getline.c | 56 +++++++++++++++++++++ libs/gst/check/libcheck/libcompat/gettimeofday.c | 49 +++++++++++++++++++ libs/gst/check/libcheck/libcompat/libcompat.c | 20 ++++++++ libs/gst/check/libcheck/libcompat/libcompat.h | 59 +++++++++++++++++++++++ libs/gst/check/libcheck/libcompat/localtime_r.c | 20 ++++++++ libs/gst/check/libcheck/libcompat/malloc.c | 41 ++++++++++++++++ libs/gst/check/libcheck/libcompat/realloc.c | 44 +++++++++++++++++ libs/gst/check/libcheck/libcompat/strdup.c | 28 +++++++++++ libs/gst/check/libcheck/libcompat/strsignal.c | 20 ++++++++ libs/gst/check/libcheck/libcompat/timer_create.c | 20 ++++++++ libs/gst/check/libcheck/libcompat/timer_delete.c | 20 ++++++++ libs/gst/check/libcheck/libcompat/timer_settime.c | 20 ++++++++ libs/gst/check/libcheck/meson.build | 31 +++++++++++- libs/gst/check/meson.build | 2 + m4/check-checks.m4 | 26 ++++++++-- meson.build | 36 +++++++++++--- 20 files changed, 565 insertions(+), 15 deletions(-) create mode 100644 libs/gst/check/libcheck/libcompat/getline.c create mode 100644 libs/gst/check/libcheck/libcompat/gettimeofday.c create mode 100644 libs/gst/check/libcheck/libcompat/malloc.c create mode 100644 libs/gst/check/libcheck/libcompat/realloc.c create mode 100644 libs/gst/check/libcheck/libcompat/strdup.c diff --git a/config.h.meson b/config.h.meson index 5d01206..d7e14e5 100644 --- a/config.h.meson +++ b/config.h.meson @@ -441,3 +441,11 @@ #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 +#mesondefine STRUCT_ITIMERSPEC_DEFINITION_MISSING +#mesondefine clockid_t +#mesondefine timer_t diff --git a/libs/gst/check/libcheck/Makefile.am b/libs/gst/check/libcheck/Makefile.am index 9a00bdc..f17dc56 100644 --- a/libs/gst/check/libcheck/Makefile.am +++ b/libs/gst/check/libcheck/Makefile.am @@ -22,10 +22,45 @@ if !HAVE_CLOCK_GETTIME CFILES += libcompat/clock_gettime.c endif +if !HAVE_GETTIMEOFDAY +CFILES += libcompat/gettimeofday.c +endif + +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 + +if !HAVE_GETLINE +CFILES += libcompat/getline.c +endif + if !HAVE_TIMER_CREATE_SETTIME_DELETE CFILES +=\ libcompat/timer_create.c \ @@ -58,3 +93,7 @@ libcheckinternal_la_LIBADD += $(PTHREAD_LIBS) else 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 diff --git a/libs/gst/check/libcheck/libcompat/alarm.c b/libs/gst/check/libcheck/libcompat/alarm.c index 9f87019..a973f22 100644 --- a/libs/gst/check/libcheck/libcompat/alarm.c +++ b/libs/gst/check/libcheck/libcompat/alarm.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" unsigned int diff --git a/libs/gst/check/libcheck/libcompat/clock_gettime.c b/libs/gst/check/libcheck/libcompat/clock_gettime.c index cc27e73..0298b35 100644 --- a/libs/gst/check/libcheck/libcompat/clock_gettime.c +++ b/libs/gst/check/libcheck/libcompat/clock_gettime.c @@ -1,9 +1,30 @@ +/* + * 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. + */ + #include "libcompat.h" #ifdef __APPLE__ #include #include #include +#include #include #endif diff --git a/libs/gst/check/libcheck/libcompat/getline.c b/libs/gst/check/libcheck/libcompat/getline.c new file mode 100644 index 0000000..edc073f --- /dev/null +++ b/libs/gst/check/libcheck/libcompat/getline.c @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include "libcompat.h" +#include + +#define INITIAL_SIZE 16 +#define DELIMITER '\n' + +ssize_t +getline (char **lineptr, size_t * n, FILE * stream) +{ + ssize_t written = 0; + int character; + + if (*lineptr == NULL || *n < INITIAL_SIZE) { + free (*lineptr); + *lineptr = (char *) malloc (INITIAL_SIZE); + *n = INITIAL_SIZE; + } + + while ((character = fgetc (stream)) != EOF) { + written += 1; + if (written >= *n) { + *n = *n * 2; + *lineptr = realloc (*lineptr, *n); + } + + (*lineptr)[written - 1] = character; + + if (character == DELIMITER) { + break; + } + } + + (*lineptr)[written] = '\0'; + + return written; +} diff --git a/libs/gst/check/libcheck/libcompat/gettimeofday.c b/libs/gst/check/libcheck/libcompat/gettimeofday.c new file mode 100644 index 0000000..78b327e --- /dev/null +++ b/libs/gst/check/libcheck/libcompat/gettimeofday.c @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#include "libcompat.h" +#include + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define EPOCHFILETIME (116444736000000000i64) +#else +#define EPOCHFILETIME (116444736000000000LL) +#endif + +int +gettimeofday (struct timeval *tv, void *tz) +{ +#if _MSC_VER + union + { + __int64 ns100; /*time since 1 Jan 1601 in 100ns units */ + FILETIME ft; + } now; + + GetSystemTimeAsFileTime (&now.ft); + tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL); + tv->tv_sec = (long) ((now.ns100 - EPOCHFILETIME) / 10000000LL); + return (0); +#else + // Return that there is no implementation of this on the system + errno = ENOSYS; + return -1; +#endif /* _MSC_VER */ +} diff --git a/libs/gst/check/libcheck/libcompat/libcompat.c b/libs/gst/check/libcheck/libcompat/libcompat.c index f550d1d..fefcf38 100644 --- a/libs/gst/check/libcheck/libcompat/libcompat.c +++ b/libs/gst/check/libcheck/libcompat/libcompat.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" /* silence warnings about an empty library */ diff --git a/libs/gst/check/libcheck/libcompat/libcompat.h b/libs/gst/check/libcheck/libcompat/libcompat.h index f09289b..d0eedaf 100644 --- a/libs/gst/check/libcheck/libcompat/libcompat.h +++ b/libs/gst/check/libcheck/libcompat/libcompat.h @@ -1,3 +1,23 @@ +/* + * 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. + */ + #ifndef LIBCOMPAT_H #define LIBCOMPAT_H @@ -84,10 +104,22 @@ CK_DLL_EXP unsigned int alarm (unsigned int seconds); #endif /* !HAVE_DECL_ALARM */ +#if !HAVE_MALLOC +CK_DLL_EXP void *rpl_malloc (size_t n); +#endif /* !HAVE_MALLOC */ + +#if !HAVE_REALLOC +CK_DLL_EXP void *rpl_realloc (void *p, size_t n); +#endif /* !HAVE_REALLOC */ + #if !HAVE_GETPID && HAVE__GETPID #define getpid _getpid #endif /* !HAVE_GETPID && HAVE__GETPID */ +#if !HAVE_GETTIMEOFDAY +CK_DLL_EXP int gettimeofday (struct timeval *tv, void *tz); +#endif /* !HAVE_GETTIMEOFDAY */ + #if !HAVE_DECL_LOCALTIME_R #if !defined(localtime_r) CK_DLL_EXP struct tm *localtime_r (const time_t * clock, struct tm *result); @@ -168,6 +200,33 @@ CK_DLL_EXP int timer_settime (timer_t timerid, int flags, CK_DLL_EXP int timer_delete (timer_t timerid); #endif /* HAVE_LIBRT */ +/* + * The following checks are to determine if the system's + * snprintf (or its variants) should be replaced with + * the C99 compliant version in libcompat. + */ +#if HAVE_CONFIG_H +#include +#endif +#if HAVE_STDARG_H +#include + +#if !HAVE_VSNPRINTF +CK_DLL_EXP int rpl_vsnprintf (char *, size_t, const char *, va_list); + +#define vsnprintf rpl_vsnprintf +#endif +#if !HAVE_SNPRINTF +CK_DLL_EXP int rpl_snprintf (char *, size_t, const char *, ...); + +#define snprintf rpl_snprintf +#endif +#endif /* HAVE_STDARG_H */ + +#if !HAVE_GETLINE +CK_DLL_EXP ssize_t getline (char **lineptr, size_t * n, FILE * stream); +#endif + /* silence warnings about an empty library */ CK_DLL_EXP void ck_do_nothing (void) diff --git a/libs/gst/check/libcheck/libcompat/localtime_r.c b/libs/gst/check/libcheck/libcompat/localtime_r.c index 682a1b4..06ac582 100644 --- a/libs/gst/check/libcheck/libcompat/localtime_r.c +++ b/libs/gst/check/libcheck/libcompat/localtime_r.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" #if !defined(localtime_r) diff --git a/libs/gst/check/libcheck/libcompat/malloc.c b/libs/gst/check/libcheck/libcompat/malloc.c new file mode 100644 index 0000000..b70a1cd --- /dev/null +++ b/libs/gst/check/libcheck/libcompat/malloc.c @@ -0,0 +1,41 @@ +/* + * 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 new file mode 100644 index 0000000..81303c3 --- /dev/null +++ b/libs/gst/check/libcheck/libcompat/realloc.c @@ -0,0 +1,44 @@ +/* + * 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/libcompat/strdup.c b/libs/gst/check/libcheck/libcompat/strdup.c new file mode 100644 index 0000000..1d6aa61 --- /dev/null +++ b/libs/gst/check/libcheck/libcompat/strdup.c @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "libcompat.h" + +char * +strdup (const char *str CK_ATTRIBUTE_UNUSED) +{ + assert (0); + return NULL; +} diff --git a/libs/gst/check/libcheck/libcompat/strsignal.c b/libs/gst/check/libcheck/libcompat/strsignal.c index 57e71cd..fd93ad5 100644 --- a/libs/gst/check/libcheck/libcompat/strsignal.c +++ b/libs/gst/check/libcheck/libcompat/strsignal.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" char * diff --git a/libs/gst/check/libcheck/libcompat/timer_create.c b/libs/gst/check/libcheck/libcompat/timer_create.c index a701781..2e250f0 100644 --- a/libs/gst/check/libcheck/libcompat/timer_create.c +++ b/libs/gst/check/libcheck/libcompat/timer_create.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" int diff --git a/libs/gst/check/libcheck/libcompat/timer_delete.c b/libs/gst/check/libcheck/libcompat/timer_delete.c index cc3ae29..5740bd6 100644 --- a/libs/gst/check/libcheck/libcompat/timer_delete.c +++ b/libs/gst/check/libcheck/libcompat/timer_delete.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" int diff --git a/libs/gst/check/libcheck/libcompat/timer_settime.c b/libs/gst/check/libcheck/libcompat/timer_settime.c index d09ba27..db2b1d5 100644 --- a/libs/gst/check/libcheck/libcompat/timer_settime.c +++ b/libs/gst/check/libcheck/libcompat/timer_settime.c @@ -1,3 +1,23 @@ +/* + * 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. + */ + #include "libcompat.h" int diff --git a/libs/gst/check/libcheck/meson.build b/libs/gst/check/libcheck/meson.build index 90f4ba1..47abadf 100644 --- a/libs/gst/check/libcheck/meson.build +++ b/libs/gst/check/libcheck/meson.build @@ -15,15 +15,39 @@ if not cdata.has('HAVE_ALARM') libcheck_files += ['libcompat/alarm.c'] endif +if not cdata.has('HAVE_GETTIMEOFDAY') + libcheck_files += ['libcompat/gettimeofday.c'] +endif + if not cdata.has('HAVE_CLOCK_GETTIME') libcheck_files += ['libcompat/clock_gettime.c'] endif +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 -# FIXME: check for symbols timer_create, timer_settime, timer_delete as well +if not cdata.has('HAVE_DECL_STRDUP') and not cdata.has('HAVE__STRDUP') + libcheck_files += ['libcompat/strdup.c'] +endif + +if not cdata.has('HAVE_GETLINE') + libcheck_files += ['libcompat/getline.c'] +endif + +# FIXME: check that timer_create, timer_settime, timer_delete are in rt_lib if not rt_lib.found() libcheck_files += [ 'libcompat/timer_create.c', @@ -42,5 +66,8 @@ libcheck = static_library('check', libcheck_files, include_directories : [configinc, internal_check_h_inc], dependencies : [rt_lib, mathlib], - c_args: gst_c_args, + 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'], pic: true) diff --git a/libs/gst/check/meson.build b/libs/gst/check/meson.build index ceb7bc8..4b5de7c 100644 --- a/libs/gst/check/meson.build +++ b/libs/gst/check/meson.build @@ -24,6 +24,8 @@ check_cdata.set('CHECK_MINOR_VERSION', 9) check_cdata.set('CHECK_MICRO_VERSION', 14) if host_machine.system() != 'windows' check_cdata.set('HAVE_FORK', 1) +else + check_cdata.set('HAVE_FORK', 0) endif subdir('libcheck') diff --git a/m4/check-checks.m4 b/m4/check-checks.m4 index ea30853..0a2cb59 100644 --- a/m4/check-checks.m4 +++ b/m4/check-checks.m4 @@ -6,8 +6,8 @@ AC_DEFUN([AG_GST_CHECK_CHECKS], AC_MSG_NOTICE([Running check unit test framework checks now...]) CHECK_MAJOR_VERSION=0 -CHECK_MINOR_VERSION=9 -CHECK_MICRO_VERSION=14 +CHECK_MINOR_VERSION=10 +CHECK_MICRO_VERSION=0 CHECK_VERSION=$CHECK_MAJOR_VERSION.$CHECK_MINOR_VERSION.$CHECK_MICRO_VERSION AC_SUBST(CHECK_MAJOR_VERSION) @@ -18,7 +18,18 @@ 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") + +dnl Check for gettimeofday() +AC_CHECK_FUNCS([gettimeofday]) +AM_CONDITIONAL(HAVE_GETTIMEOFDAY, test "x$ac_cv_func_gettimeofday" = "xyes") dnl Check for getpid() and _getpid() AC_CHECK_FUNCS([getpid _getpid]) @@ -26,6 +37,11 @@ AC_CHECK_FUNCS([getpid _getpid]) dnl Check for strdup() and _strdup() AC_CHECK_DECLS([strdup]) AC_CHECK_FUNCS([_strdup]) +AM_CONDITIONAL(HAVE_STRDUP, test "x$ac_cv_have_decl_strdup" = "xyes" -o "x$ac_cv_func__strdup" = "xyes") + +dnl Check for getline() +AC_CHECK_FUNCS([getline]) +AM_CONDITIONAL(HAVE_GETLINE, test "x$ac_cv_func_getline" = "xyes") dnl Check for mkstemp AC_CHECK_FUNCS([mkstemp]) @@ -69,9 +85,9 @@ AC_CHECK_MEMBERS([struct itimerspec.it_interval, struct itimerspec.it_value], #endif /* HAVE_PTHREAD */ ]) -dnl Check if types timer_t/clockid_t are defined. If not, we need to define -dnl it in libs/gst/check/libcheck/ibcompat.h. Note the optional inclusion of -dnl pthread.h. On MinGW(-w64), the pthread.h file contains the +dnl Check if types timer_t/clockid_t are defined. If not, we need to define it +dnl in libs/gst/check/libcheck/libcompat/libcompat.h. Note the optional +dnl inclusion of pthread.h. On MinGW(-w64), the pthread.h file contains the dnl timer_t/clockid_t definitions. AC_CHECK_TYPE(timer_t, [], [ AC_DEFINE([timer_t], [int], [timer_t]) diff --git a/meson.build b/meson.build index 82adb84..19c3639 100644 --- a/meson.build +++ b/meson.build @@ -152,6 +152,8 @@ if cc.has_function('gmtime_r', prefix : '#include') endif if cc.has_function('localtime_r', prefix : '#include') cdata.set('HAVE_LOCALTIME_R', 1) + # Needed by libcheck + cdata.set('HAVE_DECL_LOCALTIME_R', 1) endif if cc.has_function('sigaction', prefix : '#include') cdata.set('HAVE_SIGACTION', 1) @@ -230,19 +232,20 @@ else endif # ------------------------------------------------------------------------------------- -# config.h things needed by libcheck (FIXME: move into the libcheck meson.build) (tpm) +# config.h things needed by libcheck # ------------------------------------------------------------------------------------- -# FIXME: check if it is _getpid or getpid on windows (tpm) if cc.has_function('getpid', prefix : '#include \n#include ') cdata.set('HAVE_GETPID', 1) elif cc.has_function('_getpid', prefix : '#include ') - cdata.set('HAVE__GETPID', 1) + cdata.set('HAVE__GETPID', 1) # Windows (MSVC) endif -# FIXME: check for _strdup() but how/where and with what includes? (windows?) (tpm) if cc.has_function('strdup', prefix : '#include ') cdata.set('HAVE_DECL_STRDUP', 1) elif cc.has_function('_strdup', prefix : '#include ') - cdata.set('HAVE__STRDUP', 1) + cdata.set('HAVE__STRDUP', 1) # Windows (MSVC) +endif +if cc.has_function('getline', prefix : '#include ') + cdata.set('HAVE_GETLINE', 1) endif if cc.has_function('mkstemp', prefix : '#include ') cdata.set('HAVE_MKSTEMP', 1) @@ -256,12 +259,27 @@ endif if cc.has_function('alarm', prefix : '#include ') cdata.set('HAVE_ALARM', 1) endif -if cc.has_function('localtime_r', prefix : '#include ') - cdata.set('HAVE_DECL_LOCALTIME_R', 1) +if cc.has_function('gettimeofday', prefix : '#include ') + cdata.set('HAVE_GETTIMEOFDAY', 1) endif if cc.has_function('strsignal', prefix : '#include ') cdata.set('HAVE_DECL_STRSIGNAL', 1) endif +# Check for availability of types +if not cc.has_type('clockid_t', prefix : '#include ') + cdata.set('clockid_t', 'int') +endif +if not cc.has_type('timer_t', prefix : '#include ') + cdata.set('timer_t', 'int') +endif +if not cc.has_members('struct timespec', 'tv_sec', 'tv_nsec', + prefix : '#include ') + cdata.set('STRUCT_TIMESPEC_DEFINITION_MISSING', 1) +endif +if not cc.has_members('struct itimerspec', 'it_interval', 'it_value', + prefix : '#include ') + cdata.set('STRUCT_ITIMERSPEC_DEFINITION_MISSING', 1) +endif # Platform deps; only ws2_32 and execinfo for now platform_deps = [] @@ -318,7 +336,9 @@ else endif mathlib = cc.find_library('m', required : false) -rt_lib = cc.find_library('rt', required : false) # clock_gettime +# Needed for timer_create/settime/delete +# Also provides clock_gettime in glibc < 2.17 +rt_lib = cc.find_library('rt', required : false) gir = find_program('g-ir-scanner', required : false) gnome = import('gnome') -- 2.7.4