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

Reduce usage of libc #114

Merged
merged 1 commit into from
Oct 29, 2024
Merged

Reduce usage of libc #114

merged 1 commit into from
Oct 29, 2024

Conversation

notgull
Copy link
Contributor

@notgull notgull commented Sep 27, 2024

I am attempting to reduce the dependence on libc in my indirect
dependencies. While looking at this crate I noticed some low-hanging
fruit that can be very easily replaced with libc.

  • The rand() function can be re-implemented as a simple Wyrand seeded by
    the thread ID and the current time.
  • libc::memcpy is used at a point where it can be replaced with
    ptr::copy_nonoverlapping.
  • libc is used for memory allocation at a point where std::alloc can be
    used instead. So I use this.

I'm not too familiar with this codebase, so if any of these replacements
are incorrect, please let me know.

The only leftover libc call is mprotect().

I am attempting to reduce the dependence on libc in my indirect
dependencies. While looking at this crate I noticed some low-hanging
fruit that can be very easily replaced with libc.

- The rand() function can be re-implemented as a simple Wyrand seeded by
  the thread ID and the current time.
- libc::memcpy is used at a point where it can be replaced with
  ptr::copy_nonoverlapping.
- libc is used for memory allocation at a point where std::alloc can be
  used instead. So I use this.

I'm not too familiar with this codebase, so if any of these replacements
are incorrect, please let me know.

The only leftover libc call is mprotect().

Signed-off-by: John Nunley <[email protected]>
Copy link
Owner

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

Apologies for the delay.

PR looks good to me, I've got nothing particular against libc but I'm not against getting rid of a dependency (or at least getting closer to it). Thanks for this work!

@qmonnet qmonnet merged commit 404ccd0 into qmonnet:main Oct 29, 2024
7 of 8 checks passed
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.

2 participants