GithubHelp home page GithubHelp logo

rust-gmp's Introduction

Build Status

Documentation

The following functions are intentionally left out of the bindings:

  • gmp_randinit (not thread-safe, obsolete)
  • mpz_random (not thread-safe, obsolete)
  • mpz_random2 (not thread-safe, obsolete)
  • mpf_set_default_prec (not thread-safe)
  • mpf_get_default_prec (not thread-safe)
  • mpf_init (not thread-safe)
  • mpf_inits (not thread-safe, va_list wrapper)
  • mpf_clears (va_list wrapper)
  • mpf_swap (no better than rust's swap)
  • mpf_set_prec_raw (could be exposed with an unsafe function if needed)
  • mpz_inits (va_list wrapper)
  • mpz_clears (va_list wrapper)
  • mpz_swap (no better than rust's swap)
  • mpq_inits (va_list wrapper)
  • mpq_clears (va_list wrapper)
  • mpq_swap (no better than rust's swap)

rust-gmp's People

Contributors

andersk avatar dr-emann avatar ebfe avatar emberian avatar exscape avatar fizyk20 avatar goldenbadger avatar jsanders avatar leotestard avatar mhogrefe avatar michaelsproul avatar mortendahl avatar nojgaard avatar tblah avatar thestinger avatar timp3289 avatar vks avatar wizeman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-gmp's Issues

Internals should probably not be pub

I noticed that the mpz_struct inside Mpz is public, but it really shouldn't be. It's not safe to modify the contents. If clients need access to the contents, there should be safe accessors instead.

(..)::FromPrimitive is not implemented for the type (..)::Mpz

this is the behavior I'm experiencing. Let me know if you need more context. I'm also on nightly, which could just totally be screwing this up.

extern crate gmp;
extern crate num;

use self::gmp::mpz::Mpz;
use self::num::FromPrimitive;

let i = 5;
let mpz_i: Mpz = FromPrimitive::from_u64(i as u64).unwrap();

Split low-level bindings from high-level abstractions

I think there's a design tension in the library as it currently exists between providing low-level access to GMP primitives and high-level Rustic abstractions.

I think it could be good to split functionality (either internally or as two separate crates), between:

  • Unsafe FFI bindings to C functions, with gnarly GMP-style names.
  • High-level Rust abstractions with nice names, e.g. Int instead of Mpz, Rational instead of Mpq, etc. No inappropriately low-level methods like Rational::set_f (prefer From, etc).

Happy to help implement this ๐Ÿ˜„

Mpq::ratio is unsafe

Mpq::ratio is unsafe:

extern crate gmp;
use gmp::mpq::Mpq;
use gmp::mpz::Mpz;
fn main() {
    println!("{:?}", Mpq::ratio(&Mpz::one(), &-Mpz::one()));
    //                                        ^--- (!)
}

results in:

zsh: segmentation fault (core dumped)

Tested this using gmp-6.1.2 on Arch Linux.

To quote the manual:

Note that if an assignment to the numerator and/or denominator could take an mpq_t out of the canonical form described at the start of this chapter (see Rational Number Functions) then mpq_canonicalize must be called before any other mpq functions are applied to that mpq_t.

There are probably other rational functions that need to be scrutinized as well.

Mpf::get_str causes segfault

The wrapper for mpf_get_str passes it a pointer to a string of length 0. This means that when a user specifies the number of digits, the function overwrites memory starting from the empty string. This will overwrite the null on the end of the CString.

However, the fix for this is relatively simple.

When mpf_get_str has a null passed to it as the first argument, it uses malloc to create a CString of correct size, which it then returns. By using this, and then freeing the data afterwards (as to_string takes a copy), this is fixed with no memory leaks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.