From a4220d5b5feab29b32afe24bfbf360a4026bec47 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 18 Jan 2014 16:21:46 +0100 Subject: [PATCH] Fix incorrect usage of __is_sortix_foo macros in preprocessor conditionals. These macros might not be defined, in which case this usage would have generated warnings had they not been in system headers. --- libc/Makefile | 4 ++-- libc/assert/__assert.cpp | 2 +- libc/errno/errno.cpp | 4 ++-- libc/include/features.h | 14 +++++++------- libc/include/grp.h | 2 +- libc/include/pwd.h | 2 +- libc/include/stdio.h | 2 +- libc/include/stdlib.h | 2 +- libc/include/wchar.h | 2 +- libc/stdio/fsetdefaultbuf.cpp | 2 +- libc/stdlib/abort.cpp | 10 +++++++++- libc/stdlib/heap.cpp | 16 ++++++++-------- libm/Makefile | 2 +- sortix/include/sortix/resource.h | 2 +- 14 files changed, 37 insertions(+), 29 deletions(-) diff --git a/libc/Makefile b/libc/Makefile index f480861b..41893597 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -10,7 +10,7 @@ endif CPUDIR:=$(CPU) CPPINCLUDES=-I preproc -CPPFLAGS=-D__is_sortix_libc=1 $(CPPINCLUDES) +CPPFLAGS=-D__is_sortix_libc $(CPPINCLUDES) FLAGS=-Wall -Wextra $(OPTLEVEL) CFLAGS=-std=gnu99 CXXFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti @@ -517,7 +517,7 @@ INSTALLHEADERDIRS:=$(addprefix $(DESTDIR)$(INCLUDEDIR),$(patsubst preproc%,%,$(H INSTALLHEADERS:=$(addprefix $(DESTDIR)$(INCLUDEDIR),$(patsubst preproc%,%,$(HEADERS))) SORTIXOBJS:=$(addprefix sortix/,$(FREEOBJS)) -SORTIXCPPFLAGS:=$(CPPFLAGS) -D__is_sortix_kernel=1 +SORTIXCPPFLAGS:=$(CPPFLAGS) -D__is_sortix_kernel SORTIXFLAGS:=$(FLAGS) -ffreestanding SORTIXCFLAGS:=$(CFLAGS) SORTIXCXXFLAGS:=$(CXXFLAGS) diff --git a/libc/assert/__assert.cpp b/libc/assert/__assert.cpp index 2ec63332..6f63c226 100644 --- a/libc/assert/__assert.cpp +++ b/libc/assert/__assert.cpp @@ -38,7 +38,7 @@ void __assert(const char* filename, const char* function_name, const char* expression) { -#if __is_sortix_kernel +#if defined(__is_sortix_kernel) Sortix::PanicF("Assertion failure: %s:%lu: %s: %s\n", filename, line, function_name, expression); #else diff --git a/libc/errno/errno.cpp b/libc/errno/errno.cpp index a67a9418..b0dda399 100644 --- a/libc/errno/errno.cpp +++ b/libc/errno/errno.cpp @@ -25,14 +25,14 @@ #define __SORTIX_STDLIB_REDIRECTS 0 #include #include -#ifndef __is_sortix_kernel +#if !defined(__is_sortix_kernel) #include #endif extern "C" { int global_errno = 0; } extern "C" { errno_location_func_t errno_location_func = NULL; } -#ifndef __is_sortix_kernel +#if !defined(__is_sortix_kernel) extern "C" void init_error_functions() { global_errno = 0; diff --git a/libc/include/features.h b/libc/include/features.h index e4c50bd4..3739818f 100644 --- a/libc/include/features.h +++ b/libc/include/features.h @@ -28,16 +28,16 @@ #define __sortix_libc__ 1 /* Detect whether we are a core system library. */ -#if __is_sortix_libc || __is_sortix_libm +#if defined(__is_sortix_libc) || defined(__is_sortix_libm) #if !defined(__is_sortix_system_library) -#define __is_sortix_system_library 1 +#define __is_sortix_system_library #endif #endif /* Detect whether we are a core system component. */ -#if __is_sortix_kernel || __is_sortix_system_library +#if defined(__is_sortix_kernel) || defined(__is_sortix_system_library) #if !defined(__is_sortix_system_component) -#define __is_sortix_system_component 1 +#define __is_sortix_system_component #endif #endif @@ -47,7 +47,7 @@ ((gcc_major) < __GNUC__)) /* Sortix system components implicitly use the native API. */ -#if __is_sortix_system_component +#if defined(__is_sortix_system_component) #define _SORTIX_SOURCE 1 #endif @@ -72,7 +72,7 @@ #endif /* Provide the restrict keyword when building system components. */ -#if __is_sortix_system_component && !defined(__want_restrict) +#if defined(__is_sortix_system_component) && !defined(__want_restrict) #define __want_restrict 1 #endif @@ -82,7 +82,7 @@ #endif /* Provide the full in all system components. */ -#if __is_sortix_system_component +#if defined(__is_sortix_system_component) #undef __STDC_CONSTANT_MACROS #undef __STDC_LIMIT_MACROS #define __STDC_CONSTANT_MACROS diff --git a/libc/include/grp.h b/libc/include/grp.h index 7289852e..6086485d 100644 --- a/libc/include/grp.h +++ b/libc/include/grp.h @@ -43,7 +43,7 @@ struct group char* gr_passwd; }; -#if __is_sortix_libc +#if defined(__is_sortix_libc) extern FILE* __grp_file; #endif diff --git a/libc/include/pwd.h b/libc/include/pwd.h index ba598c46..5ede722e 100644 --- a/libc/include/pwd.h +++ b/libc/include/pwd.h @@ -47,7 +47,7 @@ struct passwd char* pw_shell; }; -#if __is_sortix_libc +#if defined(__is_sortix_libc) extern FILE* __pwd_file; #endif diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 176d7554..2d64a316 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -35,7 +35,7 @@ #endif #include -#if __is_sortix_libc +#if defined(__is_sortix_libc) #include #endif diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 5c3f06ea..a4d82680 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -128,7 +128,7 @@ char* getenv(const char*); int clearenv(void); #endif -#if __is_sortix_libc +#if defined(__is_sortix_libc) struct exit_handler { void (*hook)(int, void*); diff --git a/libc/include/wchar.h b/libc/include/wchar.h index b2344b3c..a6eb9d55 100644 --- a/libc/include/wchar.h +++ b/libc/include/wchar.h @@ -29,7 +29,7 @@ #include -#if __is_sortix_libc +#if defined(__is_sortix_libc) #include #endif diff --git a/libc/stdio/fsetdefaultbuf.cpp b/libc/stdio/fsetdefaultbuf.cpp index f1ce9440..b257faac 100644 --- a/libc/stdio/fsetdefaultbuf.cpp +++ b/libc/stdio/fsetdefaultbuf.cpp @@ -47,7 +47,7 @@ extern "C" int fsetdefaultbuf(FILE* fp) // Determine the buffering semantics depending on whether the destination is // an interactive device or not. -#ifdef __is_sortix_kernel +#if defined(__is_sortix_kernel) int mode = _IOLBF; // TODO: Detect this? #else int mode = fp->buffer_mode != -1 ? fp->buffer_mode diff --git a/libc/stdlib/abort.cpp b/libc/stdlib/abort.cpp index 86bc4ea9..afac3ead 100644 --- a/libc/stdlib/abort.cpp +++ b/libc/stdlib/abort.cpp @@ -37,7 +37,7 @@ extern "C" void abort(void) Sortix::PanicF("abort()"); } -#else +#elif __STDC_HOSTED__ extern "C" void abort(void) { @@ -50,4 +50,12 @@ extern "C" void abort(void) _Exit(128 + 6); } +#else + +extern "C" void abort(void) +{ + while ( true ) { }; + __builtin_unreachable(); +} + #endif diff --git a/libc/stdlib/heap.cpp b/libc/stdlib/heap.cpp index 372a75b2..1256bbda 100644 --- a/libc/stdlib/heap.cpp +++ b/libc/stdlib/heap.cpp @@ -24,7 +24,7 @@ #include -#ifndef __is_sortix_kernel +#if __STDC_HOSTED__ #include #include #include @@ -39,7 +39,7 @@ #define PARANOIA 1 -#ifdef __is_sortix_kernel +#if defined(__is_sortix_kernel) #include #include #include @@ -66,7 +66,7 @@ const size_t NUMBINS = 8UL * sizeof(size_t); static uintptr_t wilderness; -#ifdef __is_sortix_kernel +#if defined(__is_sortix_kernel) static uintptr_t GetHeapStart() { return Sortix::GetHeapLower(); @@ -195,7 +195,7 @@ inline size_t BSF(size_t Value) struct Chunk; struct Trailer; -#ifdef __is_sortix_kernel +#if defined(__is_sortix_kernel) Sortix::kthread_mutex_t heaplock; #endif @@ -407,7 +407,7 @@ extern "C" void _init_heap() wildernesssize = 0; for ( size_t i = 0; i < NUMBINS; i++ ) { bins[i] = NULL; } bincontainschunks = 0; -#ifdef __is_sortix_kernel +#if defined(__is_sortix_kernel) heaplock = Sortix::KTHREAD_MUTEX_INITIALIZER; #endif } @@ -445,7 +445,7 @@ static bool ExpandWilderness(size_t bytesneeded) extern "C" void* malloc(size_t size) { - #ifdef __is_sortix_kernel + #if defined(__is_sortix_kernel) Sortix::ScopedLock scopedlock(&heaplock); #endif @@ -619,7 +619,7 @@ static void UnifyNeighbors(Chunk** chunk) extern "C" void free(void* addr) { - #ifdef __is_sortix_kernel + #if defined(__is_sortix_kernel) Sortix::ScopedLock scopedlock(&heaplock); #endif @@ -629,7 +629,7 @@ extern "C" void free(void* addr) if ( !addr) { return; } Chunk* chunk = (Chunk*) ((uintptr_t) addr - sizeof(Chunk)); -#ifndef __is_sortix_kernel +#if __STDC_HOSTED__ if ( !IsGoodHeapPointer(addr, 1) || !IsGoodHeapPointer(chunk, sizeof(*chunk)) ) { diff --git a/libm/Makefile b/libm/Makefile index 9c536c5e..a6692243 100644 --- a/libm/Makefile +++ b/libm/Makefile @@ -352,7 +352,7 @@ CFLAGS:=$(CFLAGS) -std=gnu99 -Wall -Wextra CPPFLAGS:=$(CPPFLAGS) -I include -I src -I $(ARCH_SUBDIR) # TODO: Figure out whether these are the defines that we want to pass. -CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_libm=1 -D_MULTI_LIBM -D_POSIX_MODE +CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_libm -D_MULTI_LIBM -D_POSIX_MODE ARCH_SRCS:=$(addprefix $(ARCH_SUBDIR)/,$(ARCH_SRCS)) COMMON_SRCS:=$(addprefix src/,$(COMMON_SRCS)) diff --git a/sortix/include/sortix/resource.h b/sortix/include/sortix/resource.h index 90a4acf3..fb4a6702 100644 --- a/sortix/include/sortix/resource.h +++ b/sortix/include/sortix/resource.h @@ -56,7 +56,7 @@ struct rlimit #define RLIMIT_STACK 6 #define __RLIMIT_NUM_DECLARED 7 /* index of highest constant plus 1. */ -#if !__STDC_HOSTED__ && defined(__is_sortix_kernel) +#if defined(__is_sortix_kernel) #define RLIMIT_NUM_DECLARED __RLIMIT_NUM_DECLARED #endif