Hi! The reason Brian used to_unsafe is because that method is implicitly called when you pass something to C and the type doesn't match: crystal-lang.org/reference/1.3/syn...
So in your case if you define a to_unsafe for Z3::IntExpr that returns @expr, you could replace this:
To be honest if users call something called to_unsafe they only have themselves to blame. I just didn't want it to be called expr as that might encourage segfault-prone code.
Hi! The reason Brian used
to_unsafe
is because that method is implicitly called when you pass something to C and the type doesn't match: crystal-lang.org/reference/1.3/syn...So in your case if you define a
to_unsafe
forZ3::IntExpr
that returns@expr
, you could replace this:with this:
which might be nicer to read/write, depending on personal taste.
Is it true even if I mark
to_unsafe
asprotected
?To be honest if users call something called
to_unsafe
they only have themselves to blame. I just didn't want it to be calledexpr
as that might encourage segfault-prone code.Hm, good point. Apparently it doesn't work if
to_unsafe
isprotected
orprivate
, but I think it should. I'll ask to change that.