Skip to content

Commit

Permalink
Remove options to disable std C library
Browse files Browse the repository at this point in the history
  • Loading branch information
thetic committed Oct 30, 2022
1 parent 8cc621c commit 970fbbd
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 262 deletions.
11 changes: 3 additions & 8 deletions CMakeLists.txt
Expand Up @@ -26,9 +26,6 @@ endif()

include(CTest)

include(CMakeDependentOption)
option(CPPUTEST_STD_C_LIB_DISABLED "Disable the standard C library")

include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"int main(int argc, char ** argv) { throw 20; }"
Expand All @@ -39,11 +36,12 @@ if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL
set(is_clang_cl TRUE)
endif()

include(CMakeDependentOption)
cmake_dependent_option(CPPUTEST_STD_CPP_LIB_DISABLED "Use the standard C++ library"
OFF "NOT CPPUTEST_STD_C_LIB_DISABLED;CPPUTEST_HAVE_EXCEPTIONS" ON)
OFF "CPPUTEST_HAVE_EXCEPTIONS" ON)
option(CPPUTEST_FLAGS "Use the CFLAGS/CXXFLAGS/LDFLAGS set by CppUTest" ${PROJECT_IS_TOP_LEVEL})
cmake_dependent_option(CPPUTEST_MEM_LEAK_DETECTION_DISABLED "Enable memory leak detection"
OFF "CPPUTEST_FLAGS;NOT BORLAND;NOT CPPUTEST_STD_C_LIB_DISABLED;NOT is_clang_cl" ON)
OFF "CPPUTEST_FLAGS;NOT BORLAND;NOT is_clang_cl" ON)
option(CPPUTEST_EXTENSIONS "Use the CppUTest extension library" ON)

include(CheckTypeSize)
Expand Down Expand Up @@ -87,8 +85,6 @@ else()
set(CPP_PLATFORM Dos)
elseif(BORLAND)
set(CPP_PLATFORM Borland)
elseif(CPPUTEST_STD_C_LIB_DISABLED)
set(CPP_PLATFORM GccNoStdC)
else()
set(CPP_PLATFORM Gcc)
endif()
Expand Down Expand Up @@ -297,7 +293,6 @@ Features configured in CppUTest:
Support Long Long: ${CPPUTEST_USE_LONG_LONG}
Use CppUTest flags: ${CPPUTEST_FLAGS}
Disable Standard C library: ${CPPUTEST_STD_C_LIB_DISABLED}
Disable Standard C++ library: ${CPPUTEST_STD_CPP_LIB_DISABLED}
Generating map file: ${CPPUTEST_MAP_FILE}
Expand Down
9 changes: 1 addition & 8 deletions Makefile_using_MakefileWorker
Expand Up @@ -3,11 +3,7 @@ SILENCE = @

#--- Inputs ----#
COMPONENT_NAME = CppUTest
ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
CPP_PLATFORM = GccNoStdC
else
CPP_PLATFORM = Gcc
endif
CPP_PLATFORM = Gcc
CPPUTEST_HOME = .
OLD_MAKE = oldmake

Expand Down Expand Up @@ -49,9 +45,6 @@ test_all: start
@echo Building with overridden CXXFLAGS and CFLAGS and CPPFLAGS
$(TIME) $(MAKE_CMD) CLFAGS="" CXXFLAGS="" CPPFLAGS="-Iinclude"
$(MAKE_CMD) CFLAGS="" CXXFLAGS="" clean
@echo Building without Standard C library includes
$(TIME) $(MAKE_CMD) CPPUTEST_USE_STD_C_LIB=N all_no_tests
$(MAKE_CMD) CPPUTEST_USE_STD_C_LIB=N clean
@echo Building with a different TARGET_PLATFORM
$(MAKE_CMD) TARGET_PLATFORM=real_platform
@echo Building with overridden CXXFLAGS and CFLAGS and memory leak and STDC++ disabled
Expand Down
15 changes: 0 additions & 15 deletions build/MakefileWorker.mk
Expand Up @@ -155,11 +155,6 @@ ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
CPPUTEST_USE_MEM_LEAK_DETECTION = Y
endif

# Use the standard C library
ifndef CPPUTEST_USE_STD_C_LIB
CPPUTEST_USE_STD_C_LIB = Y
endif

# Use the standard C++ library
ifndef CPPUTEST_USE_STD_CPP_LIB
CPPUTEST_USE_STD_CPP_LIB = Y
Expand Down Expand Up @@ -294,14 +289,6 @@ endif
# derived flags in the following area
# --------------------------------------

# Without the C library, we'll need to disable the C++ library and ...
ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
CPPUTEST_USE_STD_CPP_LIB = N
CPPUTEST_USE_MEM_LEAK_DETECTION = N
CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED
CPPUTEST_CPPFLAGS += -nostdinc
endif

ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N)
CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED
else
Expand All @@ -325,10 +312,8 @@ endif

ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N)
CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED
ifeq ($(CPPUTEST_USE_STD_C_LIB), Y)
CPPUTEST_CXXFLAGS += -nostdinc++
endif
endif

ifdef $(GMOCK_HOME)
GTEST_HOME = $(GMOCK_HOME)/gtest
Expand Down
6 changes: 2 additions & 4 deletions cmake/Modules/CppUTestConfigurationOptions.cmake
Expand Up @@ -15,10 +15,8 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CppUTestWarningFlags)
endif ()

if (CPPUTEST_STD_CPP_LIB_DISABLED)
if (NOT CPPUTEST_STD_C_LIB_DISABLED AND NOT MSVC)
set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -nostdinc++")
endif ()
if (CPPUTEST_STD_CPP_LIB_DISABLED AND NOT MSVC)
set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -nostdinc++")
endif ()

if (NOT CPPUTEST_MEM_LEAK_DETECTION_DISABLED)
Expand Down
1 change: 0 additions & 1 deletion config.h.cmake
Expand Up @@ -19,7 +19,6 @@
#define _TIMESPEC_DEFINED 1
#endif

#cmakedefine CPPUTEST_STD_C_LIB_DISABLED
#cmakedefine CPPUTEST_STD_CPP_LIB_DISABLED

#cmakedefine INCLUDE_GTEST_TESTS
Expand Down
12 changes: 1 addition & 11 deletions configure.ac
Expand Up @@ -415,17 +415,7 @@ AC_ARG_ENABLE([sanitize-address], [AC_HELP_STRING([--enable-sanitize-address], [

AM_CONDITIONAL([INCLUDE_CPPUTEST_EXT], [test "x${cpputest_ext}" = xyes])

# Dealing with not having a Standard C library... (usually for Kernel development)
if test "x${use_std_c}" = xno; then
use_std_cpp=no
memory_leak_detection=no
CPPUTEST_CPPFLAGS="${CPPUTEST_CPPFLAGS} -nostdinc"
CPPUTEST_LDFLAGS="${CPPUTEST_LDFLAGS} -nostdlib"
AC_DEFINE([STD_C_LIB_DISABLED], [1], [Standard C library disabled])
CPP_PLATFORM="GccNoStdC"
else
CPP_PLATFORM="Gcc"
fi
CPP_PLATFORM="Gcc"

# Using standard C++
if test "x${use_std_cpp}" = xno; then
Expand Down
24 changes: 2 additions & 22 deletions include/CppUTest/CppUTestConfig.h
Expand Up @@ -59,16 +59,6 @@
*
*/

/* Do we use Standard C or not? When doing Kernel development, standard C usage is out. */
#ifndef CPPUTEST_USE_STD_C_LIB
#ifdef CPPUTEST_STD_C_LIB_DISABLED
#define CPPUTEST_USE_STD_C_LIB 0
#else
#define CPPUTEST_USE_STD_C_LIB 1
#endif
#endif


/* Do we use Standard C++ or not? */
#ifndef CPPUTEST_USE_STD_CPP_LIB
#ifdef CPPUTEST_STD_CPP_LIB_DISABLED
Expand Down Expand Up @@ -213,8 +203,7 @@
* Predominantly works on non-Visual C++ compilers and Visual C++ 2008 and newer
*/
#ifndef CPPUTEST_FENV_DISABLED
#if !CPPUTEST_USE_STD_C_LIB || \
(defined(_MSC_VER) && (_MSC_VER < 1800)) || \
#if (defined(_MSC_VER) && (_MSC_VER < 1800)) || \
defined(__APPLE__) || \
(defined(__ghs__) && defined(__ColdFire__)) || \
defined(__BCPLUSPLUS__)
Expand Down Expand Up @@ -249,18 +238,9 @@
#endif
#endif

/* Handling of systems with a different byte-width (e.g. 16 bit).
* Since CHAR_BIT is defined in limits.h (ANSI C), use default of 8 when building without Std C library.
*/
#if CPPUTEST_USE_STD_C_LIB
#define CPPUTEST_CHAR_BIT CHAR_BIT
#else
#define CPPUTEST_CHAR_BIT 8
#endif

/* Handling of systems with a different int-width (e.g. 16 bit).
*/
#if CPPUTEST_USE_STD_C_LIB && (INT_MAX == 0x7fff)
#if INT_MAX == 0x7fff
#define CPPUTEST_16BIT_INTS
#endif

Expand Down
47 changes: 0 additions & 47 deletions include/CppUTest/StandardCLibrary.h
Expand Up @@ -5,8 +5,6 @@
#ifndef STANDARDCLIBRARY_H_
#define STANDARDCLIBRARY_H_

#if CPPUTEST_USE_STD_C_LIB

/* Needed for size_t */
#include <stddef.h>

Expand Down Expand Up @@ -48,49 +46,4 @@
#include <string.h>
#endif

#else

#ifdef __KERNEL__

/* Unfinished and not working! Hacking hacking hacking. Why bother make the header files C++ safe! */
#define false kernel_false
#define true kernel_true
#define bool kernel_bool
#define new kernel_new
#define _Bool int
#include <linux/acpi.h>
#include <linux/types.h>
#undef false
#undef true
#undef bool
#undef new

#else

/*
* #warning "These definitions in StandardCLibrary.h are pure (educated, from linux kernel) guesses at the moment. Replace with your platform includes."
* Not on as warning are as errors :P
*/

#ifdef __SIZE_TYPE__
typedef __SIZE_TYPE__ size_t;
#else
typedef long unsigned int size_t;
#endif

#define NULL (0)
extern void* malloc(size_t);
extern void free(void *);

#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))

#define va_list __builtin_va_list
#define va_copy __builtin_va_copy
#define va_start __builtin_va_start
#define va_end __builtin_va_end

#endif

#endif

#endif
10 changes: 1 addition & 9 deletions platforms/armcc/Makefile
Expand Up @@ -42,7 +42,6 @@ TARGET_PLATFORM :=armcc_$(CPU)_$(CPU_MODE)
CPPUTEST_USE_MEM_LEAK_DETECTION := N
CPPUTEST_USE_STD_CPP_LIB := N
CPPUTEST_USE_VPATH := Y
CPPUTEST_USE_STD_C_LIB := Y
CPPUTEST_ENABLE_DEBUG := Y


Expand Down Expand Up @@ -104,14 +103,7 @@ DEP_FILES = $(call src_to_d, $(ALL_SRC))
STUFF_TO_CLEAN += $(DEP_FILES)


# Without the C library, we'll need to disable the C++ library and ...
ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
CPPUTEST_USE_STD_CPP_LIB = N
CPPUTEST_USE_MEM_LEAK_DETECTION = N
CCFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED
else
INCLUDE_DIRS +=$(SYS_INCLUDE_DIRS)
endif
INCLUDE_DIRS +=$(SYS_INCLUDE_DIRS)

ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N)
CCFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED
Expand Down
1 change: 0 additions & 1 deletion platforms/armcc/README
Expand Up @@ -22,7 +22,6 @@ For compiling CppUTest library using ARMCC, please adjust Makefile:
CPPUTEST_USE_MEM_LEAK_DETECTION := Y
CPPUTEST_USE_STD_CPP_LIB := N
CPPUTEST_USE_VPATH := Y
CPPUTEST_USE_STD_C_LIB := Y
CPPUTEST_ENABLE_DEBUG := Y

You may add additional options "CPU=xx" and "CPU_MODE=yy"
Expand Down
16 changes: 1 addition & 15 deletions platforms_examples/armcc/AT91SAM7A3/Makefile
Expand Up @@ -28,7 +28,6 @@ CPPUTEST_LIB_DIR = lib
CPPUTEST_USE_MEM_LEAK_DETECTION = N
CPPUTEST_USE_STD_CPP_LIB = Y
CPPUTEST_USE_VPATH = Y
CPPUTEST_USE_STD_C_LIB = Y
CPPUTEST_ENABLE_DEBUG = Y
CPPUTEST_USE_EXTENSIONS = N

Expand Down Expand Up @@ -125,11 +124,6 @@ ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
CPPUTEST_USE_MEM_LEAK_DETECTION = Y
endif

# Use the standard C library
ifndef CPPUTEST_USE_STD_C_LIB
CPPUTEST_USE_STD_C_LIB = Y
endif

# Use the standard C++ library
ifndef CPPUTEST_USE_STD_CPP_LIB
CPPUTEST_USE_STD_CPP_LIB = Y
Expand All @@ -149,15 +143,7 @@ ifneq ($(CPPUTEST_USE_VPATH), Y)
CPPUTEST_USE_VPATH =
endif

# Without the C library, we'll need to disable the C++ library and ...
ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
CPPUTEST_USE_STD_CPP_LIB = N
CPPUTEST_USE_MEM_LEAK_DETECTION = N
CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED
CPPUTEST_LDFLAGS +=--no_scanlib
else
INCLUDE_DIRS +=$(SYS_INCLUDE_DIRS)
endif
INCLUDE_DIRS +=$(SYS_INCLUDE_DIRS)


ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N)
Expand Down
4 changes: 2 additions & 2 deletions src/CppUTest/SimpleString.cpp
Expand Up @@ -723,7 +723,7 @@ SimpleString HexStringFrom(signed char value)
SimpleString result = StringFromFormat("%x", value);
if(value < 0) {
size_t size = result.size();
result = result.subString(size-(CPPUTEST_CHAR_BIT/4));
result = result.subString(size-(CHAR_BIT/4));
}
return result;
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ SimpleString StringFromBinaryWithSizeOrNull(const unsigned char* value, size_t s
SimpleString StringFromMaskedBits(unsigned long value, unsigned long mask, size_t byteCount)
{
SimpleString result;
size_t bitCount = (byteCount > sizeof(unsigned long)) ? (sizeof(unsigned long) * CPPUTEST_CHAR_BIT) : (byteCount * CPPUTEST_CHAR_BIT);
size_t bitCount = (byteCount > sizeof(unsigned long)) ? (sizeof(unsigned long) * CHAR_BIT) : (byteCount * CHAR_BIT);
const unsigned long msbMask = (((unsigned long) 1) << (bitCount - 1));

for (size_t i = 0; i < bitCount; i++) {
Expand Down

0 comments on commit 970fbbd

Please sign in to comment.