Coder Social home page Coder Social logo

Comments (8)

IagoAbal avatar IagoAbal commented on June 15, 2024 1

Fixed by @maurobringolf in 140e3e7 (PR #44), thanks a lot!

from haskell-z3.

IagoAbal avatar IagoAbal commented on June 15, 2024

Hi @rcdickerson, the bindings are rather low-level, and the "higher-level" Monad API is just offered for convenience but it doesn't really add any safety. In particular, if you look at the code, evalZ3 creates a new Z3 Context, and any Z3 object created inside evalZ3 is only valid for that particular Context. What you are doing here is illegal:

ast <- evalZ3 $ parseSMTLib2String "(assert true)" [] [] [] []
s <- evalZ3 $ astToString ast
...

I don't know exactly where this crashes and why it doesn't crash on some platforms or with earlier versions. That is a detail of the C++ implementation. At the high-level, the issue is that the ast belongs to the Context created by the first evalZ3, the second evalZ3 expects it to belong to its own Context. (Edited: I previously said that the first Context may have been finalized, but that shouldn't happen, it should wait for the ast to be GCed.)

You should do instead:

evalZ3 $ do
    ast <- parseSMTLib2String "(assert true)" [] [] [] []
    s    <- astToString ast
    ...

If you want that kind of flexibility then you should use Z3.Base and keep around the Context object yourself. (Note that Z3.Monad is essentially a Reader monad that stores the Context.) You don't need to call any finalizers manually though, that should be handled for you by the GC.

from haskell-z3.

rcdickerson avatar rcdickerson commented on June 15, 2024

Thanks for the response! I didn't realize there was one Context per evalZ3 -- I will restructure my code accordingly. :)

from haskell-z3.

rcdickerson avatar rcdickerson commented on June 15, 2024

So actually the same thing happens to me even with a single top-level evalZ3:

$ ghci
GHCi, version 8.4.4: http://www.haskell.org/ghc/  :? for help
Prelude> import Z3.Monad
Prelude Z3.Monad> evalZ3 $ astToString =<< parseSMTLib2String "(assert true)" [] [] [] []
double free or corruption (out)
Aborted (core dumped)

from haskell-z3.

rcdickerson avatar rcdickerson commented on June 15, 2024

I see the same thing directly using Z3.Base as well:

$ ghci
GHCi, version 8.4.4: http://www.haskell.org/ghc/  :? for help
Prelude> import Z3.Base
Prelude Z3.Base> cfg <- mkConfig
Prelude Z3.Base> ctx <- mkContext cfg
Prelude Z3.Base> ast <- parseSMTLib2String ctx "(assert (= 1 1))" [] [] [] []
Prelude Z3.Base> astToString ctx ast
double free or corruption (out)
Aborted (core dumped)

from haskell-z3.

rcdickerson avatar rcdickerson commented on June 15, 2024

As another data point, I tried this with the Python bindings as well to see if my Z3 install was the problem. Seems to work:

$ python
Python 2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from z3 import *
>>> str(parse_smt2_string("(assert (= 1 1))"))
'[1 == 1]'

from haskell-z3.

IagoAbal avatar IagoAbal commented on June 15, 2024

Sorry for taking a year or so to reply. :-) It seems to be because the Z3 folks changed the return type of the function. It used to return a Z3_ast but it now returns a Z3_ast_vector. If that is all then it should be easy to fix. Patches are welcome!

from haskell-z3.

maurobringolf avatar maurobringolf commented on June 15, 2024

I am currently trying to fix this ✌️

from haskell-z3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.