Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm working on writing Python bindings for some code that I have that uses z3.rs. I would like my bindings to be able to work seamlessly with python's z3 library (producing terms and assertions to be used in python's handle to a solver for instance). I'm writing an opinionated API around the assumption that Python is always "driving" and that we are ALWAYS using Python's global Z3 context (allocated once on first use, never dropped or moved).
Pyo3 has the requirement that any Rust type passing into Python cannot have a lifetime other than
'static
, and all my structs have the z3.rs'ctx
lifetime.I'm working around this by pulling in a pointer to Python's global
Z3_Context
and storing it in athread_local
RefCell<Z3_Context>
. I have a secondthread_local
with a'static
reference to the contents of theRefCell
.If
Context
is#[repr(transparent)]
then I believe I can safely transmute this reference into a&'static Context
, which I can then use for all my FFI types.I've already tried this and it seems to work fine, but to actually do this, I need the guarantee of
transparent
.I don't think that making this change would break anything. I assume this is also a less dangerous change for
z3.rs
to make than allowing for constructingContext
structs out of raw pointers in the high-level API.