diff options
author | Richard Biener <rguenther@suse.de> | 2023-03-06 11:06:38 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-04-18 15:39:48 +0200 |
commit | 278f8f567b5470e87e2e6482ee385d61c7f45a5d (patch) | |
tree | a32b2d5b79e0d7272e927e650db3d1d56f6490f5 /gcc/system.h | |
parent | 8b271f6069da6eee4afdbfcac72888a4551191f9 (diff) | |
download | gcc-278f8f567b5470e87e2e6482ee385d61c7f45a5d.zip gcc-278f8f567b5470e87e2e6482ee385d61c7f45a5d.tar.gz gcc-278f8f567b5470e87e2e6482ee385d61c7f45a5d.tar.bz2 |
RAII auto_mpfr and autp_mpz
The following adds two RAII classes, one for mpz_t and one for mpfr_t
making object lifetime management easier. Both formerly require
explicit initialization with {mpz,mpfr}_init and release with
{mpz,mpfr}_clear.
I've converted two example places (where lifetime is trivial).
* system.h (class auto_mpz): New,
* realmpfr.h (class auto_mpfr): Likewise.
* fold-const-call.cc (do_mpfr_arg1): Use auto_mpfr.
(do_mpfr_arg2): Likewise.
* tree-ssa-loop-niter.cc (bound_difference): Use auto_mpz;
Diffstat (limited to 'gcc/system.h')
-rw-r--r-- | gcc/system.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/system.h b/gcc/system.h index cf45db3..71d8a04 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -701,6 +701,24 @@ extern int vsnprintf (char *, size_t, const char *, va_list); /* Do not introduce a gmp.h dependency on the build system. */ #ifndef GENERATOR_FILE #include <gmp.h> + +class auto_mpz +{ +public: + auto_mpz () { mpz_init (m_mpz); } + ~auto_mpz () { mpz_clear (m_mpz); } + + operator mpz_t& () { return m_mpz; } + + auto_mpz (const auto_mpz &) = delete; + auto_mpz &operator= (const auto_mpz &) = delete; + + friend void mpz_clear (auto_mpz&) = delete; + friend void mpz_init (auto_mpz&) = delete; + +private: + mpz_t m_mpz; +}; #endif /* Get libiberty declarations. */ |