From 6e7f8534e038a131173b57f9cf899351e8242413 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 8 Jun 2016 13:41:13 -0700 Subject: [PATCH] Locally define new operator to avoid dependence on stdinc++. (#118) --- src/cli/cli_serial.cpp | 3 +-- src/core/Makefile.am | 1 + src/core/common/new.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/core/openthread.cpp | 3 +-- src/ncp/ncp.cpp | 3 +-- 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 src/core/common/new.hpp diff --git a/src/cli/cli_serial.cpp b/src/cli/cli_serial.cpp index 39bf1a7a0..279246245 100644 --- a/src/cli/cli_serial.cpp +++ b/src/cli/cli_serial.cpp @@ -31,8 +31,6 @@ * This file implements the CLI server on the serial service. */ -#include - #include #include #include @@ -43,6 +41,7 @@ #include #include #include +#include #include #include diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 0a5221a48..374218db7 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -77,6 +77,7 @@ noinst_HEADERS = \ common/encoding.hpp \ common/logging.hpp \ common/message.hpp \ + common/new.hpp \ common/tasklet.hpp \ common/timer.hpp \ crypto/aes_ccm.hpp \ diff --git a/src/core/common/new.hpp b/src/core/common/new.hpp new file mode 100644 index 000000000..93946c0ad --- /dev/null +++ b/src/core/common/new.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016, Nest Labs, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file defines the new operator used by OpenThread. + */ + +#ifndef NEW_HPP_ +#define NEW_HPP_ + +#include + +inline void *operator new(size_t, void *p) throw() { return p; } + +#endif // NEW_HPP_ diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 68ff71eea..2fe1ebafd 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -31,13 +31,12 @@ * This file implements the top-level interface to the OpenThread stack. */ -#include - #include #include #include #include #include +#include #include #include #include diff --git a/src/ncp/ncp.cpp b/src/ncp/ncp.cpp index 552678bff..a3279c8ee 100644 --- a/src/ncp/ncp.cpp +++ b/src/ncp/ncp.cpp @@ -30,9 +30,8 @@ * This file implements an HDLC interface to the Thread stack. */ -#include - #include +#include #include #include #include