Skip to content
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

maint: Avoid loading shared libraries more than once #165

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

notgull
Copy link
Contributor

@notgull notgull commented Jan 3, 2023

  • Tested on an x11 machine
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes
  • Created or updated an example program if it would help users understand this functionality

This PR makes it so the X11 linked libraries are only loaded once. This PR also replaces lazy_static with the once_cell crate, since lazy_static has largely been replaced with once_cell within the Rust ecosystem.

@AltF02 AltF02 self-requested a review January 4, 2023 12:02
@notgull
Copy link
Contributor Author

notgull commented Jan 18, 2023

@AltF02 Any chance you could take another look at this? This is a soundness issue as much as a convenience issue, since it gets rid of the bespoke unsafe code for shared library initialization.

@AltF02
Copy link
Owner

AltF02 commented Jan 18, 2023

Hi, excuses. I was very busy the past weeks

@AltF02 AltF02 merged commit 9251a04 into AltF02:master Jan 18, 2023
@AltF02
Copy link
Owner

AltF02 commented Jan 18, 2023

Released under v2.21.0

Comment on lines -40 to -42
$((stringify!($fn_name), &((*core::ptr::null::<$struct_name>()).$fn_name) as *const _ as usize),)*
$((stringify!($vfn_name), &((*core::ptr::null::<$struct_name>()).$vfn_name) as *const _ as usize),)*
$((stringify!($var_name), &((*core::ptr::null::<$struct_name>()).$var_name) as *const _ as usize),)*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also FYI, the old code that was removed here has Undefined Behavior -- offsetting a null pointer by a non-zero amount (such as to project to the field, as in this code) is not allowed. Lucky enough we have offset_of! these days which makes it much less likely that people write code like this. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants