[Bug 672] New: Inappropriate usage of assert in KDL

On Jun 15, 2009, at 08:41 , Ruben Smits wrote:

> https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=672
>
> Summary: Inappropriate usage of assert in KDL
> Product: KDL
> Version: unspecified
> Platform: All
> OS/Version: All
> Status: NEW
> Severity: normal
> Priority: P3
> Component: Primitives
> AssignedTo: orocos-dev [..] ...
> ReportedBy: ruben [dot] smits [..] ...
> CC: orocos-dev [..] ...
> Estimated Hours: 0.0
>
>
> In various places in the KDL code, asserts are used to check user
> input. This
> is not the good way to test this.
>
> We should replace it with exceptions or fault-returns.

We would strongly prefer to not be be forced to use exceptions.
Compile-time configurable as to which is used?
Stephen

[Bug 672] New: Inappropriate usage of assert in KDL

On Mon, Jun 15, 2009 at 14:43, S Roderick<kiwi [dot] net [..] ...> wrote:
> On Jun 15, 2009, at 08:41 , Ruben Smits wrote:
>
>> https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=672
>>
>>           Summary: Inappropriate usage of assert in KDL
>>           Product: KDL
>>           Version: unspecified
>>          Platform: All
>>        OS/Version: All
>>            Status: NEW
>>          Severity: normal
>>          Priority: P3
>>         Component: Primitives
>>        AssignedTo: orocos-dev [..] ...
>>        ReportedBy: ruben [dot] smits [..] ...
>>                CC: orocos-dev [..] ...
>>   Estimated Hours: 0.0
>>
>>
>> In various places in the KDL code, asserts are used to check user
>> input. This
>> is not the good way to test this.
>>
>> We should replace it with exceptions or fault-returns.
>
> We would strongly prefer to not be be forced to use exceptions.
> Compile-time configurable as to which is used?

Are you hinting towards being compilable with -fno-exceptions or towards
*as a user* not wanting to write try/catch blocks ?

For constructors, not being able to throw leads to an invalid object,
an assert is then the only way out.

&#10;#ifndef NO_EXCEPTIONS&#10;#define THROW(a) throw a&#10;#else&#10;#define THROW(a) assert( false &amp;&amp; BOOST_PP_STRINGIZE(a) )&#10;#endif&#10;

?

I don't see problems using exceptions in non-critical paths (ie
setup/constructor code) though...

Peter

Ruben Smits's picture

[Bug 672] New: Inappropriate usage of assert in KDL

I checked the usage of asserts in KDL,

we still use it in two ways:

* for index checking
* for size checking in jacobians operations and jntarray operations.

If exceptions are not the way to go then I can only remove the
checks/asserts in release code, and keep them in debug-code ( and keep
the asserts since the are taken out by adding the -DNDEBUG flag)

Ruben
On Mon, Jun 15, 2009 at 3:54 PM, Peter
Soetens<Peter [dot] Soetens [..] ...> wrote:
> On Mon, Jun 15, 2009 at 14:43, S Roderick<kiwi [dot] net [..] ...> wrote:
>> On Jun 15, 2009, at 08:41 , Ruben Smits wrote:
>>
>>> https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=672
>>>
>>>           Summary: Inappropriate usage of assert in KDL
>>>           Product: KDL
>>>           Version: unspecified
>>>          Platform: All
>>>        OS/Version: All
>>>            Status: NEW
>>>          Severity: normal
>>>          Priority: P3
>>>         Component: Primitives
>>>        AssignedTo: orocos-dev [..] ...
>>>        ReportedBy: ruben [dot] smits [..] ...
>>>                CC: orocos-dev [..] ...
>>>   Estimated Hours: 0.0
>>>
>>>
>>> In various places in the KDL code, asserts are used to check user
>>> input. This
>>> is not the good way to test this.
>>>
>>> We should replace it with exceptions or fault-returns.
>>
>> We would strongly prefer to not be be forced to use exceptions.
>> Compile-time configurable as to which is used?
>
> Are you hinting towards being compilable with -fno-exceptions or towards
> *as a user* not wanting to write try/catch blocks ?
>
> For constructors, not being able to throw leads to an invalid object,
> an assert is then the only way out.
>
> &#10;&gt; #ifndef NO_EXCEPTIONS&#10;&gt; #define THROW(a) throw a&#10;&gt; #else&#10;&gt; #define THROW(a) assert( false &amp;&amp; BOOST_PP_STRINGIZE(a) )&#10;&gt; #endif&#10;&gt;
>
> ?
>
> I don't see problems using exceptions in non-critical paths (ie
> setup/constructor code) though...
>
> Peter
> --
> Orocos-Dev mailing list
> Orocos-Dev [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-dev
>

Ruben Smits's picture

[Bug 672] New: Inappropriate usage of assert in KDL

https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=672

Summary: Inappropriate usage of assert in KDL
Product: KDL
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P3
Component: Primitives
AssignedTo: orocos-dev [..] ...
ReportedBy: ruben [dot] smits [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

In various places in the KDL code, asserts are used to check user input. This
is not the good way to test this.

We should replace it with exceptions or fault-returns.

Ruben

Ruben Smits's picture

[Bug 672] Inappropriate usage of assert in KDL

https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=672

Ruben Smits <ruben [dot] smits [..] ...> changed:

What |Removed |Added
----------------------------------------------------------------------------
Resolution| |FIXED
Status|NEW |RESOLVED

--- Comment #1 from Ruben Smits <ruben [dot] smits [..] ...> 2009-06-26 14:13:10 ---
In r30215, all asserts in the solvers are gone. I still use asserts for size
and index checking in the geometric primitives. But i have no plans on removing
these since using asserts for this purpose is quite common in c++ vector/matrix
libraries.