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

Mark bernoulli_pdf function as unsafe #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kitcatier
Copy link

@kitcatier kitcatier commented Mar 20, 2023

pub fn bernoulli_pdf(x: u32, p: f64) -> f64 {
unsafe { sys::gsl_ran_bernoulli_pdf(x, p) }
}

Hello, it is not a good choice to mark the entire function body as unsafe, which will make the caller ignore the safety requirements that the function parameters must guarantee, the developer who calls the bernoulli_pdf function may not notice this safety requirement.

Marking them unsafe also means that callers must make sure they know what they're doing.

@GuillaumeGomez
Copy link
Owner

GuillaumeGomez commented Mar 20, 2023

So I have a few questions:

  • Why only this function considering there are a lot of others which only contain a FFI function call?
  • Did you read gsl_ran_bernoulli_pdf source code before opening this PR? (You can find it here.)
  • What's the point of providing a wrapper on top of FFI if we just mark everything as unsafe?

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