diff options
author | Dave Beckett <dave@dajobe.org> | 2017-01-08 17:01:08 -0800 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2017-01-08 18:35:45 -0800 |
commit | d27769828520c941cd9d9d91a48bbf1fbe682bb0 (patch) | |
tree | be58e1abe4bca88f8b23d5806274a82129319029 | |
parent | 5e8de6d47992f85df44c754b3594af0e21a31496 (diff) | |
download | raptor-d27769828520c941cd9d9d91a48bbf1fbe682bb0.tar.gz |
Portability fixes for C11 and newer clang
Fix some RAPTOR_ASSERT_DIE() calls to have an arg value.
Add strdup.c for when it is missing and a configure check.
Write special configure.ac checks for strdup and strtok_r to work (ie fail)
when there functions are not defined in headers.
Update compiler warning arguments:
* Add -std=c11 so it'll try to use C11 if available
* Add -Wstrict-overflow
* Add -Wpedantic
* Remove -Wno-conversion -Wno-sign-conversion that are no longer warning
For clang (OSX) always add -Wno-nullability-completeness since even
stdio.h fails this.
Remove duplicate functions in AC_CHECK_FUNCS that AC_HEADER_STDC already
calls.
Move maintainer mode warning flags very early so they get picked up by
tests.
-rw-r--r-- | configure.ac | 57 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/raptor_internal.h | 4 | ||||
-rw-r--r-- | src/raptor_rdfxml.c | 3 | ||||
-rw-r--r-- | src/raptor_rss.c | 3 | ||||
-rw-r--r-- | src/raptor_uri.c | 3 | ||||
-rw-r--r-- | src/raptor_www_curl.c | 3 | ||||
-rw-r--r-- | src/strdup.c | 37 |
8 files changed, 99 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac index c769f9b4..5d664b86 100644 --- a/configure.ac +++ b/configure.ac @@ -223,15 +223,15 @@ AC_DEFUN([REDLAND_CC_TRY_FLAG], [ # http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html # # Too noisy: -# -Wconversion : conversion issues in generated lexers # -Wmissing-field-initializers : too noisy in raptor_rss_common.c # -Wsystem-headers : not debugging system -# -Wsign-conversion: : many int / unsigned int / size_t # -Wunused-parameter : variables can be marked __attribute__('unused') possible_warnings="\ +-std=c11 \ -Wall \ -Wc++-compat \ -Wextra \ +-Wpedantic \ -Wunused \ \ -Waggregate-return \ @@ -258,15 +258,14 @@ possible_warnings="\ -Wredundant-decls \ -Wshadow \ -Wsign-compare \ +-Wstrict-overflow \ -Wstrict-prototypes \ -Wswitch-enum \ -Wunreachable-code \ -Wunsafe-loop-optimizations \ -Wwrite-strings \ \ --Wno-conversion \ -Wno-missing-field-initializers \ --Wno-sign-conversion \ -Wno-system-headers \ -Wno-unused-parameter \ -Wswitch-bool \ @@ -277,12 +276,14 @@ possible_warnings="\ -Wc99-c11-compat \ " +extra_compiler_cflags="" + # compiler specific warnings if test $CC_IS_CLANG = yes; then - # Clang + # Always enable this for Clang # -Wno-nullability-completeness : too noisy on OSX reporting # warnings in stdio.h - possible_warnings="$possible_warnings \ + extra_compiler_cflags="$extra_compiler_cflags \ -Wno-nullability-completeness " fi @@ -315,12 +316,18 @@ if test "$USE_MAINTAINER_MODE" = yes; then AC_MSG_RESULT($warning_cflags) fi -MAINTAINER_CPPFLAGS="$warning_cflags" +if test "$USE_MAINTAINER_MODE" = yes; then + AC_DEFINE([MAINTAINER_MODE], [1], [Define to 1 if maintainer mode is enabled.]) + CPPFLAGS="$warning_cflags $CPPFLAGS" +fi +# Extra compiler flags to always add +CPPFLAGS="$extra_compiler_cflags $CPPFLAGS" dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(errno.h fcntl.h stdlib.h stddef.h unistd.h string.h limits.h math.h getopt.h sys/stat.h sys/param.h sys/stat.h sys/time.h setjmp.h) +dnl standard checks: memory.h stdlib.h string.h strings.h inttypes.h stdint.h sys/stat.h sys/types.h +AC_CHECK_HEADERS(errno.h fcntl.h stddef.h limits.h math.h getopt.h sys/stat.h sys/param.h sys/time.h setjmp.h) AC_CHECK_FUNCS(stat) AC_HEADER_TIME dnl FreeBSD fetch.h needs stdio.h and sys/param.h first @@ -415,10 +422,35 @@ AC_SUBST(RAPTOR_LIBTOOL_VERSION) dnl Checks for library functions. -AC_CHECK_FUNCS(gettimeofday getopt getopt_long stricmp strcasecmp vsnprintf isascii setjmp strtok_r qsort_r qsort_s) +AC_CHECK_FUNCS(gettimeofday getopt getopt_long vsnprintf isascii setjmp qsort_r qsort_s stricmp strcasecmp) + +AC_MSG_CHECKING(strdup) +have_strdup=no +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#ifdef HAVE_STRING_H +#include <string.h> +#endif +int main() { return strdup(); } +])], + [AC_MSG_RESULT(yes) + have_strdup=yes + AC_DEFINE([HAVE_STRDUP], [1], [have the strdup function])], + [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(strtok_r) +have_strtok_r=no +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#ifdef HAVE_STRING_H +#include <string.h> +#endif +int main() { return strtok_r(); } +])], + [AC_MSG_RESULT(yes) + have_strtok_r=yes + AC_DEFINE([HAVE_STRTOK_R], [1], [have the strtok_r function])], + [AC_MSG_RESULT(no)]) dnl librdfa -AM_CONDITIONAL([NEED_STRTOK_R], [test "$ac_cv_func_strtok_r" = "no"]) +AM_CONDITIONAL([NEED_STRTOK_R], [test "$have_strtok_r" = "no"]) dnl Check for GNU extension functions oCPPFLAGS="$CPPFLAGS" @@ -428,6 +460,7 @@ CPPFLAGS="$oCPPFLAGS" AM_CONDITIONAL(STRCASECMP, test $ac_cv_func_strcasecmp = no -a $ac_cv_func_stricmp = no) +AM_CONDITIONAL(STRDUP, test $have_strdup = no) AM_CONDITIONAL(GETOPT, test $ac_cv_func_getopt = no -a $ac_cv_func_getopt_long = no) @@ -1307,10 +1340,6 @@ if test "$debug_messages" = "yes"; then AC_DEFINE([RAPTOR_DEBUG], [1], [Define to 1 if debug messages are enabled.]) fi -if test "$USE_MAINTAINER_MODE" = yes; then - AC_DEFINE([MAINTAINER_MODE], [1], [Define to 1 if maintainer mode is enabled.]) - CPPFLAGS="$MAINTAINER_CPPFLAGS $CPPFLAGS" -fi AC_SUBST(RAPTOR_LDFLAGS) diff --git a/src/Makefile.am b/src/Makefile.am index 3378d104..966a64da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -166,6 +166,9 @@ endif if STRCASECMP libraptor2_la_SOURCES += strcasecmp.c endif +if STRDUP +libraptor2_la_SOURCES += strdup.c +endif if PARSEDATE libraptor2_la_SOURCES += parsedate.c BUILT_SOURCES += parsedate.c diff --git a/src/raptor_internal.h b/src/raptor_internal.h index bb80acbb..4f360763 100644 --- a/src/raptor_internal.h +++ b/src/raptor_internal.h @@ -768,6 +768,10 @@ int raptor_check_ordinal(const unsigned char *name); #endif #endif +#ifndef HAVE_STRDUP +#define strdup raptor_strdup +char* raptor_strdup(const char* s); +#endif /* raptor_nfc_icu.c */ int raptor_nfc_icu_check (const unsigned char* string, size_t len, int *error); diff --git a/src/raptor_rdfxml.c b/src/raptor_rdfxml.c index d1e4bb57..ce9f3931 100644 --- a/src/raptor_rdfxml.c +++ b/src/raptor_rdfxml.c @@ -29,6 +29,9 @@ #include <stdio.h> #include <string.h> +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif #include <ctype.h> #include <stdarg.h> #ifdef HAVE_ERRNO_H diff --git a/src/raptor_rss.c b/src/raptor_rss.c index f43a1f9f..ebbbbbb5 100644 --- a/src/raptor_rss.c +++ b/src/raptor_rss.c @@ -28,6 +28,9 @@ #include <stdio.h> #include <string.h> +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif #include <ctype.h> #include <stdarg.h> #ifdef HAVE_ERRNO_H diff --git a/src/raptor_uri.c b/src/raptor_uri.c index 42ed5c11..1ace31f7 100644 --- a/src/raptor_uri.c +++ b/src/raptor_uri.c @@ -29,6 +29,9 @@ #include <stdio.h> #include <string.h> +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif #include <ctype.h> #include <stdarg.h> #ifdef HAVE_ERRNO_H diff --git a/src/raptor_www_curl.c b/src/raptor_www_curl.c index a99057f3..ea660585 100644 --- a/src/raptor_www_curl.c +++ b/src/raptor_www_curl.c @@ -31,6 +31,9 @@ #include <stdio.h> #include <string.h> +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif #include <stdarg.h> /* Raptor includes */ diff --git a/src/strdup.c b/src/strdup.c new file mode 100644 index 00000000..22aa451b --- /dev/null +++ b/src/strdup.c @@ -0,0 +1,37 @@ +/* -*- Mode: c; c-basic-offset: 2 -*- + * + * strdup.c - strdup compatibility + * + * This file is in the public domain. + * + */ + +#ifdef HAVE_CONFIG_H +#include <raptor_config.h> +#endif + +#include <string.h> +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif + +/* for RAPTOR_MALLOC() */ +#include "raptor2.h" +#include "raptor_internal.h" + + +char* +raptor_strdup(const char* s) +{ + size_t len; + char *buf; + + if(!s) + return NULL; + + len = strlen(s) + 1; + buf = RAPTOR_MALLOC(char*, len); + if(buf) + memcpy(buf, s, len); + return buf; +} |