From 08858e10fa4a01ea85d44c76ff7848db5a95c084 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 10 Dec 2018 19:44:07 -0500 Subject: [PATCH] kernel_cpp: Don't import all of the "std" namespace. This file is included, directly or indirectly, by most of the kernel-space C++ code, and so importing the entirety of "std" seriously pollutes the global namespace. So instead, just import "std::nothrow", which is the only thing we really want in the global namespace. Tested on both GCC2 and GCC7 and seems to work just fine. While I'm here, also update the include guards and copyright header to match the standard format used elsewhere. --- headers/private/kernel/util/kernel_cpp.h | 19 ++++---- .../drivers/ports/pc_serial/kernel_cpp.h | 45 ------------------- 2 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 src/add-ons/kernel/drivers/ports/pc_serial/kernel_cpp.h diff --git a/headers/private/kernel/util/kernel_cpp.h b/headers/private/kernel/util/kernel_cpp.h index 4709db51a4..39416a4ff7 100644 --- a/headers/private/kernel/util/kernel_cpp.h +++ b/headers/private/kernel/util/kernel_cpp.h @@ -1,10 +1,10 @@ -#ifndef KERNEL_CPP_H -#define KERNEL_CPP_H -/* cpp - C++ in the kernel -** -** Initial version by Axel Dörfler, axeld@pinc-software.de -** This file may be used under the terms of the MIT License. -*/ +/* + * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2004-2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_UTIL_KERNEL_CPP_H +#define _KERNEL_UTIL_KERNEL_CPP_H #ifdef __cplusplus @@ -13,8 +13,7 @@ #if _KERNEL_MODE || _LOADER_MODE -using namespace std; -extern const nothrow_t std::nothrow; +using std::nothrow; // We need new() versions we can use when also linking against libgcc. // std::nothrow can't be used since it's defined in both libgcc and @@ -47,4 +46,4 @@ extern void operator delete[](void* ptr, std::size_t) _NOEXCEPT; #endif // __cplusplus -#endif /* KERNEL_CPP_H */ +#endif /* _KERNEL_UTIL_KERNEL_CPP_H */ diff --git a/src/add-ons/kernel/drivers/ports/pc_serial/kernel_cpp.h b/src/add-ons/kernel/drivers/ports/pc_serial/kernel_cpp.h deleted file mode 100644 index 7d7b025872..0000000000 --- a/src/add-ons/kernel/drivers/ports/pc_serial/kernel_cpp.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _KERNEL_CPP_H_ -#define _KERNEL_CPP_H_ - -#include - -inline void * -operator new(size_t size) -{ - return malloc(size); -} - - -inline void * -operator new[](size_t size) -{ - return malloc(size); -} - - -inline void -operator delete(void *pointer) -{ - free(pointer); -} - - -inline void -operator delete[](void *pointer) -{ - free(pointer); -} - - -inline void -terminate(void) -{ -} - - -static inline void -__throw() -{ -} - -#endif // _KERNEL_CPP_H_