-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace uses of bare assert
with OPENSIM_ASSERT
#3548
Changes from 9 commits
c52e660
0ab6994
38c6dbd
7d9f5df
9c35c07
e30a0c4
91223e2
11a2b3f
5984f33
d88052e
b0d0c2c
08b8a28
1a6f86d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* ------------------------------------------------------------------------- * | ||
* OpenSim: Assertion.cpp * | ||
* -------------------------------------------------------------------------- * | ||
* The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * | ||
* See http://opensim.stanford.edu and the NOTICE file for more information. * | ||
* OpenSim is developed at Stanford University and supported by the US * | ||
* National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * | ||
* through the Warrior Web program. * | ||
* * | ||
* Copyright (c) 2005-2023 Stanford University and the Authors * | ||
* Author(s): Adam Kewley * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain a * | ||
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
* -------------------------------------------------------------------------- */ | ||
|
||
#include "Assertion.h" | ||
|
||
#include <OpenSim/Common/Exception.h> | ||
|
||
void OpenSim::OnAssertionError( | ||
char const* failingCode, | ||
char const* failingFile, | ||
char const* failingFunction, | ||
unsigned int failingLine, | ||
Object const* maybeSourceObject) | ||
{ | ||
if (maybeSourceObject) { | ||
throw Exception{failingFile, failingLine, failingFunction, *maybeSourceObject, failingCode}; | ||
} | ||
else { | ||
throw Exception{failingFile, failingLine, failingFunction, failingCode}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef OPENSIM_ASSERTION_H_ | ||
#define OPENSIM_ASSERTION_H_ | ||
|
||
/* ------------------------------------------------------------------------- * | ||
* OpenSim: Assertion.h * | ||
* -------------------------------------------------------------------------- * | ||
* The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * | ||
* See http://opensim.stanford.edu and the NOTICE file for more information. * | ||
* OpenSim is developed at Stanford University and supported by the US * | ||
* National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * | ||
* through the Warrior Web program. * | ||
* * | ||
* Copyright (c) 2005-2023 Stanford University and the Authors * | ||
* Author(s): Adam Kewley * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain a * | ||
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
* -------------------------------------------------------------------------- */ | ||
|
||
#include "osimCommonDLL.h" | ||
|
||
namespace OpenSim { | ||
|
||
class Object; | ||
|
||
[[noreturn]] OSIMCOMMON_API void OnAssertionError( | ||
char const* failingCode, | ||
char const* failingFile, | ||
char const* failingFunction, | ||
unsigned int failingLine, | ||
Object const* maybeSourceObject = nullptr | ||
); | ||
} | ||
|
||
#define OPENSIM_ASSERT_ALWAYS(CONDITION) \ | ||
static_cast<bool>(CONDITION) ? static_cast<void>(0) : OpenSim::OnAssertionError(#CONDITION, __FILE__, __func__, __LINE__) | ||
#define OPENSIM_ASSERT_FRMOBJ_ALWAYS(CONDITION) \ | ||
static_cast<bool>(CONDITION) ? static_cast<void>(0) : OpenSim::OnAssertionError(#CONDITION, __FILE__, __func__, __LINE__, this) | ||
|
||
#if defined(NDEBUG) | ||
#define OPENSIM_ASSERT(CONDITION) | ||
#define OPENSIM_ASSERT_FRMOBJ(CONDITION) | ||
#else | ||
#define OPENSIM_ASSERT(CONDITION) OPENSIM_ASSERT_ALWAYS(CONDITION) | ||
#define OPENSIM_ASSERT_FRMOBJ(CONDITION) OPENSIM_ASSERT_FRMOBJ_ALWAYS(CONDITION) | ||
#endif | ||
|
||
#endif // OPENSIM_ASSERTION_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ | |
// INCLUDES | ||
#include <iostream> | ||
#include <string> | ||
#include <cassert> | ||
#include "osimCommonDLL.h" | ||
#include "Exception.h" | ||
#include "IO.h" | ||
|
@@ -58,12 +57,6 @@ exception() | |
setMessage(aMsg); | ||
_file = aFile; | ||
_line = aLine; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also a drive-by edit that was made because I was using regex to flag uses of |
||
// make it assert false when debugging... | ||
//#ifndef NDEBUG | ||
// print(cout); | ||
// assert(false); | ||
//#endif | ||
} | ||
|
||
namespace { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a drive-by edit, but is included here because:
throw
)assert(false)
is surplus, turns up in regex searches for bareassert
s, and is compiler-toggleableexit
(and mystd::terminate
) are also surplus, but I wasn't sure whether something funny could be going on (e.g. disabling exceptions or something unusual), so I just replaced theexit
, with the more C++stdlib-friendlystd::terminate()