fix and check shifting issue

The exception raised by << and >> when shifting mark_t by too many
bits are only enabled in SPOT_DEBUG, as those operations are quite
low-level.  However we were always testing them, and although we
wanted them to be active in Python, it was not always the case.

* spot/twa/acc.hh: introduce max_accsets() as
a static constexpr method, so we can see it in Python.
* spot/misc/bitset.hh: Fix preprocessing directive
so the check is actually enabled when compiling the Python
bindings.
* bin/autcross.cc, bin/autfilt.cc, bin/ltlcross.cc: Use max_accsets().
* tests/core/acc.cc: Comment out the shifting exception when
SPOT_DEBUG is unset.
* tests/python/except.py: Make sure the exception is always raised in
Python.
This commit is contained in:
Alexandre Duret-Lutz 2018-05-25 11:29:59 +02:00
parent 23e0d718fd
commit b12eb0508f
7 changed files with 75 additions and 38 deletions

View file

@ -64,8 +64,10 @@ int main()
auto m1 = spot::acc_cond::mark_t({0, 2});
auto m2 = spot::acc_cond::mark_t({0, 3});
auto m3 = spot::acc_cond::mark_t({2, 1});
auto m4 = spot::acc_cond::mark_t({0, SPOT_MAX_ACCSETS - 2});
if (!(m4.min_set() == 1 && m4.max_set() == SPOT_MAX_ACCSETS - 1))
auto m4 =
spot::acc_cond::mark_t({0, spot::acc_cond::mark_t::max_accsets() - 2});
if (!((m4.min_set() == 1) &&
(m4.max_set() == spot::acc_cond::mark_t::max_accsets() - 1)))
return 1;
spot::acc_cond::mark_t m0 = {};
@ -184,33 +186,39 @@ int main()
assert(c1 == c2);
try
{
spot::acc_cond a{SPOT_MAX_ACCSETS + 1};
}
{
spot::acc_cond a{spot::acc_cond::mark_t::max_accsets() + 1};
}
catch (const std::runtime_error& e)
{
assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30));
}
{
assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30));
}
#if SPOT_DEBUG
// Those error message are disabled in non-debugging code as
// shifting mark_t is usually done in the innermost loop of
// algorithms. However, they are still done in Python, and we
// test them in python/except.py
try
{
spot::acc_cond::mark_t m{0};
m <<= spot::acc_cond::mark_t::max_accsets() + 1;
}
catch (const std::runtime_error& e)
{
assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30));
}
try
{
spot::acc_cond::mark_t m{0};
m <<= SPOT_MAX_ACCSETS + 1;
}
{
spot::acc_cond::mark_t m{0};
m >>= spot::acc_cond::mark_t::max_accsets() + 1;
}
catch (const std::runtime_error& e)
{
assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30));
}
try
{
spot::acc_cond::mark_t m{0};
m >>= SPOT_MAX_ACCSETS + 1;
}
catch (const std::runtime_error& e)
{
assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30));
}
{
assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30));
}
#endif
return 0;
}