config: Check strtok_s capability.
Also cleans up redundancies and adds pragma in `UNUSED` macro.
This commit is contained in:
parent
4148d3d5d4
commit
786e70dd1b
6 changed files with 33 additions and 29 deletions
12
.cmake/Modules/Capabilities.cmake
Normal file
12
.cmake/Modules/Capabilities.cmake
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Copyright (C) 2015 Franklin "Snaipe" Mathieu.
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the LICENSE file distributed with Criterion.
|
||||
|
||||
include(CheckPrototypeDefinition)
|
||||
|
||||
check_prototype_definition(
|
||||
strtok_s
|
||||
"char *strtok_s(char *strToken, const char *strDelimit, char **context)"
|
||||
NULL
|
||||
"string.h"
|
||||
HAVE_STRTOK_S)
|
|
@ -8,6 +8,7 @@ set(LIBCSPTR_DISABLE_TESTS ON)
|
|||
set(LIBCSPTR_DISABLE_COVERALLS ON)
|
||||
|
||||
include(Submodules)
|
||||
include(Capabilities)
|
||||
|
||||
if (MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
# define CR_NORETURN CR_ATTRIBUTE(noreturn)
|
||||
# define CR_INLINE CR_ATTRIBUTE(always_inline) inline
|
||||
# elif CR_IS_MSVC
|
||||
# define CR_UNUSED
|
||||
# define CR_UNUSED __pragma(warning(suppress:4100))
|
||||
# define CR_NORETURN __declspec(noreturn)
|
||||
# define CR_INLINE __forceinline
|
||||
# else
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#cmakedefine ENABLE_NLS @ENABLE_NLS@
|
||||
#cmakedefine HAVE_PCRE @HAVE_PCRE@
|
||||
#cmakedefine ENABLE_VALGRIND_ERRORS @ENABLE_VALGRIND_ERRORS@
|
||||
#cmakedefine01 HAVE_STRTOK_S
|
||||
|
||||
# define LOCALEDIR "${LOCALEDIR}"
|
||||
# define PACKAGE "${PROJECT_NAME}"
|
||||
|
|
|
@ -37,8 +37,13 @@
|
|||
#include "common.h"
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
// fallback to strtok on windows since strtok_s is not available everywhere
|
||||
# define strtok_r(str, delim, saveptr) strtok(str, delim)
|
||||
# if HAVE_STRTOK_S
|
||||
# define strtok_r strtok_s
|
||||
# else
|
||||
static char *strtok_r(char *str, const char *delim, CR_UNUSED char **saveptr) {
|
||||
return strtok(str, delim);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -161,13 +166,8 @@ void normal_log_post_all(struct criterion_global_stats *stats) {
|
|||
void normal_log_assert(struct criterion_assert_stats *stats) {
|
||||
if (!stats->passed) {
|
||||
char *dup = strdup(*stats->message ? stats->message : "");
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
char *line = strtok(dup, "\n");
|
||||
#else
|
||||
char *saveptr = NULL;
|
||||
char *line = strtok_r(dup, "\n", &saveptr);
|
||||
#endif
|
||||
|
||||
bool sf = criterion_options.short_filename;
|
||||
criterion_pimportant(CRITERION_PREFIX_DASHES,
|
||||
|
@ -176,11 +176,7 @@ void normal_log_assert(struct criterion_assert_stats *stats) {
|
|||
CR_FG_RED, stats->line, CR_RESET,
|
||||
line);
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
while ((line = strtok(NULL, "\n")))
|
||||
#else
|
||||
while ((line = strtok_r(NULL, "\n", &saveptr)))
|
||||
#endif
|
||||
criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_desc), line);
|
||||
free(dup);
|
||||
}
|
||||
|
@ -235,13 +231,8 @@ void normal_log_test_timeout(CR_UNUSED struct criterion_test_stats *stats) {
|
|||
void normal_log_test_abort(CR_UNUSED struct criterion_test_stats *stats, const char *msg) {
|
||||
|
||||
char *dup = strdup(msg);
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
char *line = strtok(dup, "\n");
|
||||
#else
|
||||
char *saveptr = NULL;
|
||||
char *line = strtok_r(dup, "\n", &saveptr);
|
||||
#endif
|
||||
|
||||
criterion_pimportant(CRITERION_PREFIX_DASHES,
|
||||
_(msg_test_abort),
|
||||
|
@ -249,11 +240,7 @@ void normal_log_test_abort(CR_UNUSED struct criterion_test_stats *stats, const c
|
|||
stats->test->name,
|
||||
line);
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
while ((line = strtok(NULL, "\n")))
|
||||
#else
|
||||
while ((line = strtok_r(NULL, "\n", &saveptr)))
|
||||
#endif
|
||||
criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_desc), line);
|
||||
|
||||
free(dup);
|
||||
|
|
|
@ -34,6 +34,16 @@
|
|||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
#ifdef VANILLA_WIN32
|
||||
# if HAVE_STRTOK_S
|
||||
# define strtok_r strtok_s
|
||||
# else
|
||||
static char *strtok_r(char *str, const char *delim, CR_UNUSED char **saveptr) {
|
||||
return strtok(str, delim);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define strdup _strdup
|
||||
#endif
|
||||
|
@ -69,22 +79,15 @@ static void print_test_normal(struct criterion_test_stats *stats) {
|
|||
for (struct criterion_assert_stats *asrt = stats->asserts; asrt; asrt = asrt->next) {
|
||||
if (!asrt->passed) {
|
||||
char *dup = strdup(*asrt->message ? asrt->message : "");
|
||||
#ifdef VANILLA_WIN32
|
||||
char *line = strtok(dup, "\n");
|
||||
#else
|
||||
char *saveptr = NULL;
|
||||
char *line = strtok_r(dup, "\n", &saveptr);
|
||||
#endif
|
||||
bool sf = criterion_options.short_filename;
|
||||
criterion_important(" %s:%u: Assertion failed: %s\n",
|
||||
sf ? basename_compat(asrt->file) : asrt->file,
|
||||
asrt->line,
|
||||
line);
|
||||
#ifdef VANILLA_WIN32
|
||||
while ((line = strtok(NULL, "\n")))
|
||||
#else
|
||||
|
||||
while ((line = strtok_r(NULL, "\n", &saveptr)))
|
||||
#endif
|
||||
criterion_important(" %s\n", line);
|
||||
free(dup);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue