mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 06:07:48 +00:00
[utils] add a flag to use std new (#11937)
The noexcept placement new is standard in c++11. This commit adds a config OPENTHREAD_CONFIG_USE_STD_NEW to allow using <new>. The default behavior is still using OpenThread's own placement new implementation.
This commit is contained in:
@@ -617,6 +617,15 @@
|
|||||||
#define OPENTHREAD_EXAMPLES_SIMULATION 0
|
#define OPENTHREAD_EXAMPLES_SIMULATION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def OPENTHREAD_CONFIG_USE_STD_NEW
|
||||||
|
*
|
||||||
|
* Define 1 to enable using std <new>.
|
||||||
|
*/
|
||||||
|
#ifndef OPENTHREAD_CONFIG_USE_STD_NEW
|
||||||
|
#define OPENTHREAD_CONFIG_USE_STD_NEW 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,10 +34,16 @@
|
|||||||
#ifndef OT_INCLUDE_COMMON_NEW_HPP_
|
#ifndef OT_INCLUDE_COMMON_NEW_HPP_
|
||||||
#define OT_INCLUDE_COMMON_NEW_HPP_
|
#define OT_INCLUDE_COMMON_NEW_HPP_
|
||||||
|
|
||||||
|
#include <openthread/config.h>
|
||||||
|
|
||||||
|
#if defined(OPENTHREAD_CONFIG_USE_STD_NEW) && OPENTHREAD_CONFIG_USE_STD_NEW
|
||||||
|
#include <new> // IWYU pragma: keep
|
||||||
|
#else
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <openthread/platform/toolchain.h>
|
#include <openthread/platform/toolchain.h>
|
||||||
|
|
||||||
inline void *operator new(size_t, void *p) throw() { return p; }
|
inline void *operator new(size_t, void *p) throw() { return p; }
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // OT_INCLUDE_COMMON_NEW_HPP_
|
#endif // OT_INCLUDE_COMMON_NEW_HPP_
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
option(OT_BUILD_GTEST "enable gtest")
|
option(OT_BUILD_GTEST "enable gtest")
|
||||||
|
|
||||||
if(OT_FTD AND BUILD_TESTING AND (NOT OT_PLATFORM STREQUAL "nexus"))
|
if(OT_FTD AND BUILD_TESTING AND (NOT OT_PLATFORM STREQUAL "nexus"))
|
||||||
|
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_USE_STD_NEW=1")
|
||||||
add_subdirectory(unit)
|
add_subdirectory(unit)
|
||||||
if(OT_BUILD_GTEST)
|
if(OT_BUILD_GTEST)
|
||||||
add_subdirectory(gtest)
|
add_subdirectory(gtest)
|
||||||
|
|||||||
@@ -26,8 +26,6 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Disable OpenThread's own new implementation to avoid duplicate definition
|
|
||||||
#define OT_INCLUDE_COMMON_NEW_HPP_
|
|
||||||
#include "test_platform.h"
|
#include "test_platform.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|||||||
Reference in New Issue
Block a user