Skip to content

Commit

Permalink
Replace NDEBUG with custom flags to avoid ABI issues (#1796)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Mar 24, 2024
1 parent a51e08c commit 8931e2c
Show file tree
Hide file tree
Showing 49 changed files with 2,518 additions and 2,100 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,17 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)

set(BUILD_TYPE_DEBUG FALSE)
set(BUILD_TYPE_RELEASE FALSE)
set(BUILD_TYPE_RELWITHDEBINFO FALSE)
set(BUILD_TYPE_MINSIZEREL FALSE)
set(DART_BUILD_MODE_DEBUG FALSE)
set(DART_BUILD_MODE_RELEASE FALSE)

if("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "DEBUG")
set(BUILD_TYPE_DEBUG TRUE)
set(DART_BUILD_MODE_DEBUG TRUE)
elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELEASE")
set(BUILD_TYPE_RELEASE TRUE)
set(DART_BUILD_MODE_RELEASE TRUE)
elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELWITHDEBINFO")
set(BUILD_TYPE_RELWITHDEBINFO TRUE)
set(DART_BUILD_MODE_RELEASE TRUE)
elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "MINSIZEREL")
set(BUILD_TYPE_MINSIZEREL TRUE)
set(DART_BUILD_MODE_RELEASE TRUE)
else()
message(WARNING "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} unknown. Valid options are: Debug | Release | RelWithDebInfo | MinSizeRel")
endif()
Expand All @@ -167,14 +165,14 @@ endif()
# - ERROR: To enable log with DART_ERROR() and below
# - FATAL: To enable log with DART_FATAL()
# - OFF: To turn off all the logs
if(BUILD_TYPE_DEBUG)
if(DART_BUILD_MODE_DEBUG)
set(DART_ACTIVE_LOG_LEVEL "DEBUG" CACHE STRING "Compile time active log level to enable")
else()
set(DART_ACTIVE_LOG_LEVEL "INFO" CACHE STRING "Compile time active log level to enable")
endif()
set_property(CACHE DART_ACTIVE_LOG_LEVEL PROPERTY STRINGS TRACE DEBUG INFO WARN ERROR FATAL OFF)

if(BUILD_TYPE_DEBUG)
if(DART_BUILD_MODE_DEBUG)
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
else()
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
Expand Down
2 changes: 1 addition & 1 deletion dart/collision/Option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#pragma message( \
"This header has been deprecated in DART 6.1. " \
"Please include CollisionOption.hpp intead.")
"Please include CollisionOption.hpp instead.")

#include "dart/collision/CollisionOption.hpp"

Expand Down
2 changes: 1 addition & 1 deletion dart/collision/Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#pragma message( \
"This header has been deprecated in DART 6.1. " \
"Please include CollisionResult.hpp intead.")
"Please include CollisionResult.hpp instead.")

#include "dart/collision/CollisionResult.hpp"

Expand Down
2 changes: 1 addition & 1 deletion dart/common/FreeListAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void FreeListAllocator::MemoryBlockHeader::merge(MemoryBlockHeader* other)
}

//==============================================================================
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
bool FreeListAllocator::MemoryBlockHeader::isValid() const
{
if (mPrev != nullptr && mPrev->mNext != this)
Expand Down
2 changes: 1 addition & 1 deletion dart/common/FreeListAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class FreeListAllocator : public MemoryAllocator
/// Merges this memory block with the given memory block
void merge(MemoryBlockHeader* other);

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
/// [Debug only] Returns whether this memory block is valid
bool isValid() const;
#endif
Expand Down
3 changes: 2 additions & 1 deletion dart/common/Macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <cassert>

#include "dart/common/Logging.hpp"
#include "dart/config.hpp"

// DART_NUM_ARGS(<arg1> [, <arg2> [, ...]])
#define DETAIL_DART_NUM_ARGS(z, a, b, c, d, e, f, cnt, ...) cnt
Expand Down Expand Up @@ -68,7 +69,7 @@
#define DETAIL_DART_ASSERT_2(condition, message) assert((condition) && #message)
#define DART_ASSERT(...) \
DART_CONCAT(DETAIL_DART_ASSERT_, DART_NUM_ARGS(__VA_ARGS__)) \
(__VA_ARGS__)
(__VA_ARGS__)

// Macro to mark the function is not implemented
#define DART_NOT_IMPLEMENTED \
Expand Down
1 change: 1 addition & 0 deletions dart/common/MemoryAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <string>

#include "dart/common/Castable.hpp"
#include "dart/config.hpp"

namespace dart::common {

Expand Down
10 changes: 5 additions & 5 deletions dart/common/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "dart/common/MemoryManager.hpp"

#ifndef NDEBUG // debug
#if DART_BUILD_MODE_DEBUG
#include "dart/common/Logging.hpp"
#endif

Expand All @@ -49,7 +49,7 @@ MemoryManager& MemoryManager::GetDefault()
MemoryManager::MemoryManager(MemoryAllocator& baseAllocator)
: mBaseAllocator(baseAllocator),
mFreeListAllocator(mBaseAllocator),
#ifdef NDEBUG
#if DART_BUILD_MODE_RELEASE
mPoolAllocator(mFreeListAllocator)
#else
mPoolAllocator(mFreeListAllocator.getInternalAllocator())
Expand All @@ -73,7 +73,7 @@ MemoryAllocator& MemoryManager::getBaseAllocator()
//==============================================================================
FreeListAllocator& MemoryManager::getFreeListAllocator()
{
#ifdef NDEBUG
#if DART_BUILD_MODE_RELEASE
return mFreeListAllocator;
#else
return mFreeListAllocator.getInternalAllocator();
Expand All @@ -83,7 +83,7 @@ FreeListAllocator& MemoryManager::getFreeListAllocator()
//==============================================================================
PoolAllocator& MemoryManager::getPoolAllocator()
{
#ifdef NDEBUG
#if DART_BUILD_MODE_RELEASE
return mPoolAllocator;
#else
return mPoolAllocator.getInternalAllocator();
Expand Down Expand Up @@ -146,7 +146,7 @@ void MemoryManager::deallocateUsingPool(void* pointer, size_t bytes)
deallocate(Type::Pool, pointer, bytes);
}

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
//==============================================================================
bool MemoryManager::hasAllocated(void* pointer, size_t size) const noexcept
{
Expand Down
8 changes: 4 additions & 4 deletions dart/common/MemoryManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef DART_COMMON_MEMORYMANAGER_HPP_
#define DART_COMMON_MEMORYMANAGER_HPP_

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
#include <mutex>
#endif
#include <iostream>
Expand Down Expand Up @@ -151,7 +151,7 @@ class MemoryManager final
template <typename T>
void destroyUsingPool(T* pointer) noexcept;

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
/// Returns true if a pointer is allocated by the internal allocator.
[[nodiscard]] bool hasAllocated(void* pointer, size_t size) const noexcept;
#endif
Expand All @@ -164,10 +164,10 @@ class MemoryManager final
std::ostream& os, const MemoryManager& memoryManager);

private:
/// The base allocator to allocate memory chunck.
/// The base allocator to allocate memory chunk.
MemoryAllocator& mBaseAllocator;

#ifdef NDEBUG
#if DART_BUILD_MODE_RELEASE
/// The free list allocator.
FreeListAllocator mFreeListAllocator;

Expand Down
7 changes: 3 additions & 4 deletions dart/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@
#define DART_COMPILER_MSVC
#endif

#cmakedefine01 BUILD_TYPE_DEBUG
#cmakedefine01 BUILD_TYPE_RELEASE
#cmakedefine01 BUILD_TYPE_RELWITHDEBINFO
#cmakedefine01 BUILD_TYPE_MINSIZEREL
// Indicates the build mode used for compiling
#cmakedefine01 DART_BUILD_MODE_DEBUG
#cmakedefine01 DART_BUILD_MODE_RELEASE

#cmakedefine01 HAVE_NLOPT
#cmakedefine01 HAVE_IPOPT
Expand Down
6 changes: 3 additions & 3 deletions dart/constraint/BoxedLcpConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "dart/constraint/BoxedLcpConstraintSolver.hpp"

#include <cassert>
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
#include <iomanip>
#include <iostream>
#endif
Expand Down Expand Up @@ -155,7 +155,7 @@ void BoxedLcpConstraintSolver::solveConstrainedGroup(ConstrainedGroup& group)
return;

const int nSkip = dPAD(n);
#ifdef NDEBUG // release
#if DART_BUILD_MODE_RELEASE
mA.resize(n, nSkip);
#else // debug
mA.setZero(n, nSkip);
Expand Down Expand Up @@ -310,7 +310,7 @@ void BoxedLcpConstraintSolver::solveConstrainedGroup(ConstrainedGroup& group)
}

//==============================================================================
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
bool BoxedLcpConstraintSolver::isSymmetric(std::size_t n, double* A)
{
std::size_t nSkip = dPAD(n);
Expand Down
4 changes: 2 additions & 2 deletions dart/constraint/BoxedLcpConstraintSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ class BoxedLcpConstraintSolver : public ConstraintSolver
/// Cache data for boxed LCP formulation
Eigen::VectorXi mOffset;

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
private:
/// Return true if the matrix is symmetric
bool isSymmetric(std::size_t n, double* A);

/// Return true if the diagonla block of matrix is symmetric
/// Return true if the diagonal block of matrix is symmetric
bool isSymmetric(
std::size_t n, double* A, std::size_t begin, std::size_t end);

Expand Down
2 changes: 1 addition & 1 deletion dart/constraint/BoxedLcpSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BoxedLcpSolver : public common::Castable<BoxedLcpSolver>
bool earlyTermination = false)
= 0;

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
virtual bool canSolve(int n, const double* A) = 0;
#endif
};
Expand Down
2 changes: 1 addition & 1 deletion dart/constraint/ConstrainedGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ConstrainedGroup::removeAllConstraints()
}

//==============================================================================
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
bool ConstrainedGroup::containConstraint(
const ConstConstraintBasePtr& _constraint) const
{
Expand Down
3 changes: 2 additions & 1 deletion dart/constraint/ConstrainedGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <Eigen/Dense>

#include "dart/config.hpp"
#include "dart/constraint/SmartPointer.hpp"

namespace dart {
Expand Down Expand Up @@ -100,7 +101,7 @@ class ConstrainedGroup
friend class ConstraintSolver;

private:
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
/// Return true if _constraint is contained
bool containConstraint(const ConstConstraintBasePtr& _constraint) const;
#endif
Expand Down
2 changes: 1 addition & 1 deletion dart/constraint/DantzigBoxedLcpSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool DantzigBoxedLcpSolver::solve(
n, A, x, b, nullptr, 0, lo, hi, findex, earlyTermination);
}

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
//==============================================================================
bool DantzigBoxedLcpSolver::canSolve(int /*n*/, const double* /*A*/)
{
Expand Down
2 changes: 1 addition & 1 deletion dart/constraint/DantzigBoxedLcpSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DantzigBoxedLcpSolver : public BoxedLcpSolver
int* findex,
bool earlyTermination) override;

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
// Documentation inherited.
bool canSolve(int n, const double* A) override;
#endif
Expand Down
6 changes: 3 additions & 3 deletions dart/constraint/DantzigLCPSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "dart/constraint/DantzigLCPSolver.hpp"

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
#include <iomanip>
#include <iostream>
#endif
Expand Down Expand Up @@ -79,7 +79,7 @@ void DantzigLCPSolver::solve(ConstrainedGroup* _group)
int* findex = new int[n];

// Set w to 0 and findex to -1
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
std::memset(A, 0.0, n * nSkip * sizeof(double));
#endif
std::memset(w, 0.0, n * sizeof(double));
Expand Down Expand Up @@ -189,7 +189,7 @@ void DantzigLCPSolver::solve(ConstrainedGroup* _group)
}

//==============================================================================
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
bool DantzigLCPSolver::isSymmetric(std::size_t _n, double* _A)
{
std::size_t nSkip = dPAD(_n);
Expand Down
6 changes: 3 additions & 3 deletions dart/constraint/DantzigLCPSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace dart {
namespace constraint {

/// \deprecated This header has been deprecated in DART 6.7. Please include
/// DantzigBoxedLcpSolver.hpp intead.
/// DantzigBoxedLcpSolver.hpp instead.
///
/// DantzigLCPSolver is a LCP solver that uses ODE's implementation of Dantzig
/// algorithm
Expand All @@ -58,12 +58,12 @@ class DantzigLCPSolver : public LCPSolver
// Documentation inherited
void solve(ConstrainedGroup* _group) override;

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
private:
/// Return true if the matrix is symmetric
bool isSymmetric(std::size_t _n, double* _A);

/// Return true if the diagonla block of matrix is symmetric
/// Return true if the diagonal block of matrix is symmetric
bool isSymmetric(
std::size_t _n, double* _A, std::size_t _begin, std::size_t _end);

Expand Down
4 changes: 2 additions & 2 deletions dart/constraint/JointConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void JointConstraint::getInformation(ConstraintInfo* lcp)
if (!mActive[i])
continue;

#ifndef NDEBUG // debug
#if DART_BUILD_MODE_DEBUG
if (std::abs(lcp->w[index]) > 1e-6)
{
dterr << "Invalid " << index
Expand All @@ -418,7 +418,7 @@ void JointConstraint::getInformation(ConstraintInfo* lcp)
lcp->lo[index] = mImpulseLowerBound[i];
lcp->hi[index] = mImpulseUpperBound[i];

#ifndef NDEBUG // debug
#if DART_BUILD_MODE_DEBUG
if (lcp->findex[index] != -1)
{
dterr << "Invalid " << index
Expand Down
2 changes: 1 addition & 1 deletion dart/constraint/JointLimitConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void JointLimitConstraint::getInformation(ConstraintInfo* lcp)
lcp->lo[index] = mLowerBound[i];
lcp->hi[index] = mUpperBound[i];

#ifndef NDEBUG // Debug mode
#if DART_BUILD_MODE_DEBUG
if (lcp->lo[index] > lcp->hi[index])
{
std::cout << "dim: " << mDim << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions dart/constraint/PGSLCPSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "dart/constraint/PGSLCPSolver.hpp"

#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
#include <iomanip>
#include <iostream>
#endif
Expand Down Expand Up @@ -72,7 +72,7 @@ void PGSLCPSolver::solve(ConstrainedGroup* _group)
int* findex = new int[n];

// Set w to 0 and findex to -1
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
std::memset(A, 0.0, n * nSkip * sizeof(double));
#endif
std::memset(w, 0.0, n * sizeof(double));
Expand Down Expand Up @@ -185,7 +185,7 @@ void PGSLCPSolver::solve(ConstrainedGroup* _group)
}

//==============================================================================
#ifndef NDEBUG
#if DART_BUILD_MODE_DEBUG
bool PGSLCPSolver::isSymmetric(std::size_t _n, double* _A)
{
std::size_t nSkip = dPAD(_n);
Expand Down
Loading

0 comments on commit 8931e2c

Please sign in to comment.