UAVCAN_IMPLEMENT_PLACEMENT_NEW

This commit is contained in:
Pavel Kirienko
2014-05-05 19:28:28 +04:00
parent 8c8732d051
commit 581ee43231
5 changed files with 41 additions and 3 deletions
+1 -1
View File
@@ -7,9 +7,9 @@
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <new>
#include <uavcan/stdint.hpp>
#include <uavcan/util/templates.hpp>
#include <uavcan/util/placement_new.hpp>
#include <uavcan/impl_constants.hpp>
namespace uavcan
@@ -82,6 +82,16 @@
# include <cstdio>
#endif
/**
* Some C++ implementations are half-broken and do not implement the placement new operator.
* Setting this preprocessor symbol to 1 makes libuavcan implement its own operator new (std::size_t, void*),
* and its delete counterpart.
* This option may be removed in future.
*/
#ifndef UAVCAN_IMPLEMENT_PLACEMENT_NEW
# define UAVCAN_IMPLEMENT_PLACEMENT_NEW 0
#endif
namespace uavcan
{
@@ -5,7 +5,6 @@
#pragma once
#include <cstdlib>
#include <new>
#include <uavcan/error.hpp>
#include <uavcan/impl_constants.hpp>
#include <uavcan/util/templates.hpp>
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#include <cstddef>
#include <uavcan/impl_constants.hpp>
#ifndef UAVCAN_IMPLEMENT_PLACEMENT_NEW
# error UAVCAN_IMPLEMENT_PLACEMENT_NEW
#endif
#if UAVCAN_IMPLEMENT_PLACEMENT_NEW
inline void* operator new (std::size_t, void* ptr) throw()
{
return ptr;
}
inline void* operator new[](std::size_t, void* ptr) throw()
{
return ptr;
}
inline void operator delete (void*, void*) throw() { }
inline void operator delete[](void*, void*) throw() { }
#else
# include <new>
#endif
@@ -5,7 +5,6 @@
#include <uavcan/transport/transfer_buffer.hpp>
#include <cassert>
#include <cstdlib>
#include <new>
namespace uavcan
{