-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define a macro to create self-referencing type and use it for font face #184
Conversation
This makes unsafe part be more concentrated and allows reuse. The macro would be used in later patch.
3e88e53
to
509ba26
Compare
Have we considered using |
There was, but dropped for compilation time reason. 95e3624 Though it's not a big issue for me.. The produced type is basically equivalent to expansion of ouroboros macro so I think it's fine. And this macro should still be faster than ouroboros as we didn't use proc-macro here. |
Imo if this will be using custom unsafe, then it is easier to verify the soundness of a particular implementation rather than a generic macro. Also, the current implementation has a soundness issue, but it is not too surprising since this was just fixed in ouroboros someguynamedjosh/ouroboros#88. I can make a PR for this later today. |
mod owned_face { | ||
impl_self_ref!(OwnedFace, rustybuzz::Face<'static>, rustybuzz::Face<'this>); | ||
} | ||
use owned_face::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapping this up in a module is necessary to prevent accessing the fields incorrectly so it should probably be part of the macro
@Imberflur After roughly look at the issue you mentioned, and given the motivation of not using |
/// this struct | ||
pub struct $SelfRef<T> { | ||
/// `data_ref` could self-referencing `data` | ||
data_ref: $RefStatic, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field needs to be wrapped in maybe_dangling::MaybeDangling
or core::mem::MaybeUninit
to prevent the compiler from potentially assuming any references it contains will be valid till the end of a function when $SelfRef<T>
is passed as a function parameter (see the issue I linked above). Any such references will only be valid until this value is dropped.
That definitely seems like the best approach. We could have removed the extra layer of indirection from the |
This makes unsafe part be more concentrated and allows reuse. The macro would be used in later patch.