version 1.1.1.2, 2000/09/09 14:12:15 |
version 1.1.1.3, 2003/08/25 16:06:00 |
|
|
/* Memory allocation routines. |
/* Memory allocation routines. |
|
|
Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc. |
Copyright 1991, 1993, 1994, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
|
This file is part of the GNU MP Library. |
This file is part of the GNU MP Library. |
|
|
Line 25 MA 02111-1307, USA. */ |
|
Line 25 MA 02111-1307, USA. */ |
|
#include "gmp.h" |
#include "gmp.h" |
#include "gmp-impl.h" |
#include "gmp-impl.h" |
|
|
#ifdef __NeXT__ |
|
#define static |
|
#endif |
|
|
|
|
void * (*__gmp_allocate_func) _PROTO ((size_t)) = __gmp_default_allocate; |
|
void * (*__gmp_reallocate_func) _PROTO ((void *, size_t, size_t)) |
|
= __gmp_default_reallocate; |
|
void (*__gmp_free_func) _PROTO ((void *, size_t)) = __gmp_default_free; |
|
|
void * (*_mp_allocate_func) _PROTO ((size_t)) = _mp_default_allocate; |
|
void * (*_mp_reallocate_func) _PROTO ((void *, size_t, size_t)) |
|
= _mp_default_reallocate; |
|
void (*_mp_free_func) _PROTO ((void *, size_t)) = _mp_default_free; |
|
|
|
|
|
/* Default allocation functions. In case of failure to allocate/reallocate |
/* Default allocation functions. In case of failure to allocate/reallocate |
an error message is written to stderr and the program aborts. */ |
an error message is written to stderr and the program aborts. */ |
|
|
void * |
void * |
#if __STDC__ |
__gmp_default_allocate (size_t size) |
_mp_default_allocate (size_t size) |
|
#else |
|
_mp_default_allocate (size) |
|
size_t size; |
|
#endif |
|
{ |
{ |
void *ret; |
void *ret; |
#ifdef DEBUG |
#ifdef DEBUG |
Line 55 _mp_default_allocate (size) |
|
Line 46 _mp_default_allocate (size) |
|
ret = malloc (size); |
ret = malloc (size); |
if (ret == 0) |
if (ret == 0) |
{ |
{ |
perror ("cannot allocate in gmp"); |
fprintf (stderr, "GNU MP: Cannot allocate memory (size=%u)\n", size); |
abort (); |
abort (); |
} |
} |
|
|
Line 73 _mp_default_allocate (size) |
|
Line 64 _mp_default_allocate (size) |
|
} |
} |
|
|
void * |
void * |
#if __STDC__ |
__gmp_default_reallocate (void *oldptr, size_t old_size, size_t new_size) |
_mp_default_reallocate (void *oldptr, size_t old_size, size_t new_size) |
|
#else |
|
_mp_default_reallocate (oldptr, old_size, new_size) |
|
void *oldptr; |
|
size_t old_size; |
|
size_t new_size; |
|
#endif |
|
{ |
{ |
void *ret; |
void *ret; |
|
|
Line 110 _mp_default_reallocate (oldptr, old_size, new_size) |
|
Line 94 _mp_default_reallocate (oldptr, old_size, new_size) |
|
ret = realloc (oldptr, new_size); |
ret = realloc (oldptr, new_size); |
if (ret == 0) |
if (ret == 0) |
{ |
{ |
perror ("cannot allocate in gmp"); |
fprintf (stderr, "GNU MP: Cannot reallocate memory (old_size=%u new_size=%u)\n", old_size, new_size); |
abort (); |
abort (); |
} |
} |
|
|
Line 128 _mp_default_reallocate (oldptr, old_size, new_size) |
|
Line 112 _mp_default_reallocate (oldptr, old_size, new_size) |
|
} |
} |
|
|
void |
void |
#if __STDC__ |
__gmp_default_free (void *blk_ptr, size_t blk_size) |
_mp_default_free (void *blk_ptr, size_t blk_size) |
|
#else |
|
_mp_default_free (blk_ptr, blk_size) |
|
void *blk_ptr; |
|
size_t blk_size; |
|
#endif |
|
{ |
{ |
#ifdef DEBUG |
#ifdef DEBUG |
{ |
{ |