diff --git a/libexactreal/exact-real/cppyy.hpp b/libexactreal/exact-real/cppyy.hpp index bf871743..b25b5368 100644 --- a/libexactreal/exact-real/cppyy.hpp +++ b/libexactreal/exact-real/cppyy.hpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "element.hpp" @@ -96,15 +95,11 @@ auto optional_rational(const Element &element) { return static_cast std::string serialize(const T &value) { - // We use the deprecated strstream to work around a segfault on macOS. The - // segfault does not happen here on macOS but with the print() below. In any - // case, we are trying to use the same code path for both use cases. - std::strstream serialized; + std::ostringstream serialized; { Archive archive(serialized); archive(value); } - serialized << std::ends; return serialized.str(); } @@ -123,17 +118,9 @@ T deserialize(const std::string &serialized) { // boost::yap::print fails to instantiate on macOS so we wrap it here. template std::string print(const Expr& expr) { - // Mysteriously, when using a stringstream on macOS, we get a segfault with - // this code unless we explicitly terminate the stream with an std::ends. - // (However, the ends then shows up as an explicit null terminator in the - // string and no such null terminator should be necessary with a - // stringstream. With a (deprecated) strstream, the null terminator is - // however necessary and everything just works, so we keep this as a - // workaround for the time being.) - std::strstream os; + std::ostringstream os; boost::yap::print(os, expr); - os << std::ends; return os.str(); } } // namespace cppyy diff --git a/pyexactreal/src/pyexactreal/cppyy_exactreal.py b/pyexactreal/src/pyexactreal/cppyy_exactreal.py index fef38b07..c1994e77 100644 --- a/pyexactreal/src/pyexactreal/cppyy_exactreal.py +++ b/pyexactreal/src/pyexactreal/cppyy_exactreal.py @@ -146,9 +146,7 @@ def enable_yap(proxy, name): >>> from pyexactreal import exactreal >>> a = exactreal.Arb(1) >>> b = a + a; b - expr<+> - term[=1.00000] - term[=1.00000] + arithmetic expression >>> b(64) 2.00000 >>> b += b @@ -226,11 +224,7 @@ class Yap(object): >>> a += a >>> a += a >>> a - expr<+> - expr<+> const & - expr<+> const & - expr<+> const & - ... + arithmetic expression >>> a(64) 16.0000 @@ -369,19 +363,20 @@ def __repr__(self): r""" Return a printable representation of this Yap expression. - EXAMPLES: + .. NOTE: - We use Yap's own debug printer. It's quite verbose:: + Previously, we used Yap's debug printer. While it works fine most of + the time, we ran into spurious segfauls on macOS in CI runs. Therefore, + we disabled such fancy printing here, in particular, because we + probably want to get rid of most of this overly fancy Arb wrap. >>> from pyexactreal import exactreal >>> a = exactreal.Arb(1) >>> a + a - expr<+> - term[=1.00000] - term[=1.00000] + arithmetic expression """ - return cppyy.gbl.exactreal.cppyy.print(self.value).strip() + return "arithmetic expression" def makeModule(traits, gens, ring=None): r""" diff --git a/pyexactreal/test/arb.py b/pyexactreal/test/arb.py index 034a6285..f21ccae8 100755 --- a/pyexactreal/test/arb.py +++ b/pyexactreal/test/arb.py @@ -36,7 +36,7 @@ def test_arithmetic(): b += a # expressions do not get evaluated without specifying a precision - assert str(a + a).startswith("expr<+>") + assert str(a + a) == "arithmetic expression" assert -(-a) == a diff --git a/pyexactreal/test/arf.py b/pyexactreal/test/arf.py index 947c05f8..abb4fd63 100755 --- a/pyexactreal/test/arf.py +++ b/pyexactreal/test/arf.py @@ -32,7 +32,7 @@ def test_arithmetic(): b = Arf(2) # Expressions do not get evaluated without specifying a precision/rounding - assert str(a + a).startswith("expr<+>") + assert str(a + a) == "arithmetic expression" assert (a + a)(64, Arf.Round.DOWN) == b