Add GMP initialization
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
c7a1623d27
commit
5a0801789b
1 changed files with 39 additions and 0 deletions
39
src/util/gmp_init.cpp
Normal file
39
src/util/gmp_init.cpp
Normal 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;
|
||||
|
Loading…
Reference in a new issue