De-serializing expressions with MPFR crashes

13 views
Skip to first unread message

Saleh Jamali

unread,
Apr 15, 2024, 8:44:35 AMApr 15
to symengine
Greetings,

I am struggling to de-serialize an expression that was serialized with symengine::Basic::dumps() . 

The reason I am posting this here is that I am not sure if I am 100% correct the way I am using the real numbers. 

Anyway, here is a simple code to reproduce it:

```
#include <iostream>
#include <symengine/basic.h>
#include <symengine/real_mpfr.h>
#include <symengine/add.h>
#include <symengine/printers/strprinter.h>

using namespace SymEngine;

SymEngine::RCP<const SymEngine::Basic> RealMpfrNew(float val) {
    SymEngine::mpfr_class m1(53);
    mpfr_set_flt(m1.get_mpfr_t(), val, MPFR_RNDN);
    return SymEngine::real_mpfr(std::move(m1));
}

int main() {
    RCP<const Basic> x = symbol("x");
    RCP<const Basic> y = symbol("y");
    RCP<const Basic> z = symbol("z");
    StrPrinter printer;

    // passes
    {
        auto e = add({mul({RealMpfrNew(2.35f), x, y}), mul({x, z}), mul({y, z})});
        std::cout << "e: " << printer.apply(e) << std::endl;
        auto e_loaded = Basic::loads(e->dumps());
        std::cout << "e_loaded: " << printer.apply(e_loaded) << std::endl;
        std::cout << "T1 passed." << std::endl<< std::endl << std::endl;
    }

    // crashes
    {
        auto e = add({mul({RealMpfrNew(2.35f), x, y}), mul({x, z}), mul({RealMpfrNew(4.35f), y, z})});
        std::cout << "e: " << printer.apply(e) << std::endl;
        auto e_loaded = Basic::loads(e->dumps());
        std::cout << "e_loaded: " << printer.apply(e_loaded) << std::endl;
        std::cout << "T2 passed." << std::endl << std::endl << std::endl;
    }
}
```

Could you please have a look and advise me on how to approach this issue? So far I have tried these releases: 0.10.1, 0.11.2 (archlinux)


```
$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Linker supports --exclude-libs
--------------------------------------------------------------------------------

+-------------------------------+
| Configuration results SUMMARY |
+-------------------------------+

CMAKE_C_COMPILER:   /usr/bin/cc
CMAKE_CXX_COMPILER: /usr/bin/c++
CMAKE_BUILD_TYPE: Release
CMAKE_CONFIGURATION_TYPES:
CMAKE_C_FLAGS:          
CMAKE_CXX_FLAGS:         -std=c++11  -fPIC
CMAKE_CXX_FLAGS_DEBUG:   -Wall -Wextra -Wno-unused-parameter -fno-common -g -ggdb -Wno-unknown-pragmas
CMAKE_CXX_FLAGS_RELEASE: -Wall -Wextra -Wno-unused-parameter -fno-common -O3 -funroll-loops -Wno-unknown-pragmas
CMAKE_INSTALL_PREFIX: /usr/local
BUILD_SHARED_LIBS:
INTEGER_CLASS : GMP
HAVE_SYMENGINE_GMP: yes
WITH_SYMENGINE_ASSERT: no
WITH_SYMENGINE_RCP: ON
WITH_SYMENGINE_TEUCHOS: no
WITH_COTIRE: no
WITH_GENERATE_PARSER: no
HAVE_GCC_ABI_DEMANGLE: yes
HAVE_C_FUNCTION_NOT_FUNC: no
HAVE_DEFAULT_CONSTRUCTORS: yes
HAVE_SYMENGINE_NOEXCEPT: yes
HAVE_SYMENGINE_IS_CONSTRUCTIBLE: yes
HAVE_SYMENGINE_RESERVE: yes
HAVE_SYMENGINE_STD_TO_STRING: TRUE
WITH_SYMENGINE_THREAD_SAFE: ON
BUILD_TESTS: yes
BUILD_BENCHMARKS: OFF
BUILD_BENCHMARKS_GOOGLE: no
WITH_GMP: yes
GMP_INCLUDE_DIRS: /usr/include
GMP_LIBRARIES: /usr/lib/libgmp.so
WITH_BFD: no
WITH_ECM: no
WITH_PRIMESIEVE: no
WITH_FLINT: no
WITH_ARB: no
WITH_MPFR: ON
MPFR_INCLUDE_DIRS: /usr/include
MPFR_LIBRARIES: /usr/lib/libmpfr.so
WITH_PIRANHA: no
WITH_LLVM: no
WITH_BOOST: no
WITH_PTHREAD: no
WITH_MPC: no
WITH_TCMALLOC: no
WITH_OPENMP: no
WITH_VIRTUAL_TYPEID: no
LIBS: mpfr;gmp

--------------------------------------------------------------------------------

-- Configuring done (0.6s)
-- Generating done (0.1s)
```

Isuru Fernando

unread,
Apr 15, 2024, 1:33:27 PMApr 15
to syme...@googlegroups.com
Hi Saleh,

This should be fixed in https://github.com/symengine/symengine/pull/2013

Isuru

--
You received this message because you are subscribed to the Google Groups "symengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symengine+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/symengine/f66b9de2-3454-433d-b9a3-d63e103ac33fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages