From 5a0801789b83fad2bb30842a5e3aacf7ea55dcd3 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Tue, 16 Jul 2013 10:29:17 -0700 Subject: [PATCH] Add GMP initialization Signed-off-by: Leonardo de Moura --- src/util/gmp_init.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/util/gmp_init.cpp diff --git a/src/util/gmp_init.cpp b/src/util/gmp_init.cpp new file mode 100644 index 000000000..386c96d34 --- /dev/null +++ b/src/util/gmp_init.cpp @@ -0,0 +1,39 @@ +/* +Copyright (c) 2013 Microsoft Corporation. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. + +Author: Leonardo de Moura +*/ +#include +#include +#include + +extern "C" void * cxx_malloc(size_t size) { + void * p = malloc(size); + if (p != 0 || size == 0) + return p; + + throw std::bad_alloc(); +} + +extern "C" void * cxx_realloc(void * q, size_t, size_t new_size) { + void* p = realloc(q, new_size); + if (p != 0 || new_size == 0) + return p; + + throw std::bad_alloc(); +} + +extern "C" void cxx_free(void * p, size_t) { + free(p); +} + +class gmp_init { +public: + gmp_init() { + mp_set_memory_functions(cxx_malloc, cxx_realloc, cxx_free); + } +}; + +gmp_init g_gmp_init; +