Add GMP initialization

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-07-16 10:29:17 -07:00
parent c7a1623d27
commit 5a0801789b

39
src/util/gmp_init.cpp Normal file
View file

@ -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 <new>
#include <gmp.h>
#include <cstdlib>
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;