Closed
Description
In this situation:
// type jit_context_t = *mut Struct__jit_context;
pub struct Context {
priv jcx: ffi::jit_context_t
}
impl Context {
/// Create a new Context. Returns None on out-of-memory (as libjit does)
pub fn new() -> Option<Context> {
unsafe {
ffi::jit_init();
let x: ffi::jit_context_t = ffi::jit_context_create();
if x == null() {
None
} else {
Some(Context { jcx: x })
}
}
}
}
Ideally I'd be storing jcx
as some non-nullable pointer, such that Option<Context>
could be a single word. Unfortunately there is no type usable today. Option<*mut T>
is 16 bytes on x86_64, and will always be at least one byte more than just the pointer. Option<~T>
will be 8 bytes, but needs handling about the destructor and also has aliasability guarantees, which will be invalidated by the underlying libjit code. Option<&'static mut T>
also has aliasing concerns, on top of nasty lifetime hack.
There is no pointer type usable to get zero overhead in this. Given the decision on #10571 (which I agree with!) it would be nice to have something usable here. Perhaps even a #[not_null]
attribute, per-field, could be usable?
Metadata
Metadata
Assignees
Labels
No labels