From 56eb43e3ca9e1274a5b39bf4e2bd266bd8cb525a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 3 Nov 2008 13:15:12 +0000 Subject: [PATCH] * Made kernel_cpp.h usable in the runtime loader. * Added new(mynothrow) operators which avoid clashes when also linking against libgcc. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28474 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/util/kernel_cpp.h | 36 +++++++++++++++--------- src/system/kernel/util/kernel_cpp.cpp | 4 ++- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/headers/private/kernel/util/kernel_cpp.h b/headers/private/kernel/util/kernel_cpp.h index 5a22f3cb72..c5c5373f32 100644 --- a/headers/private/kernel/util/kernel_cpp.h +++ b/headers/private/kernel/util/kernel_cpp.h @@ -11,20 +11,16 @@ #include #include -#if _KERNEL_MODE +#if _KERNEL_MODE || _LOADER_MODE using namespace std; extern const nothrow_t std::nothrow; -// Oh no! C++ in the kernel! Are you nuts? -// -// - no exceptions -// - (almost) no virtuals (well, the Query code now uses them) -// - it's basically only the C++ syntax, and type checking -// - since one tend to encapsulate everything in classes, it has a slightly -// higher memory overhead -// - nicer code -// - easier to maintain +// 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 +// kernel_cpp.cpp. +typedef struct {} mynothrow_t; +extern const mynothrow_t mynothrow; inline void * @@ -34,7 +30,7 @@ operator new(size_t size) throw (std::bad_alloc) // keep the prototype as specified in , or else GCC 3 // won't like us return malloc(size); -} +} inline void * @@ -42,7 +38,7 @@ operator new[](size_t size) throw (std::bad_alloc) { return malloc(size); } - + inline void * operator new(size_t size, const std::nothrow_t &) throw () @@ -58,11 +54,25 @@ operator new[](size_t size, const std::nothrow_t &) throw () } +inline void * +operator new(size_t size, const mynothrow_t &) throw () +{ + return malloc(size); +} + + +inline void * +operator new[](size_t size, const mynothrow_t &) throw () +{ + return malloc(size); +} + + inline void operator delete(void *ptr) throw () { free(ptr); -} +} inline void diff --git a/src/system/kernel/util/kernel_cpp.cpp b/src/system/kernel/util/kernel_cpp.cpp index b6ced31b90..adfd45c7f3 100644 --- a/src/system/kernel/util/kernel_cpp.cpp +++ b/src/system/kernel/util/kernel_cpp.cpp @@ -1,7 +1,7 @@ /* * Copyright 2003-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. - * + * * Authors: * Axel Dörfler, axeld@pinc-software.de. * Ingo Weinhold, bonefish@users.sf.net. @@ -38,6 +38,8 @@ const nothrow_t std::nothrow = {}; # endif #endif +const mynothrow_t mynothrow = {}; + #if __GNUC__ == 2 extern "C" void