umf_realloc.c
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ========================================================================== */
/* === UMF_realloc ========================================================== */
/* ========================================================================== */
/* -------------------------------------------------------------------------- */
/* UMFPACK Copyright (c) Timothy A. Davis, CISE, */
/* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
/* web: http://www.cise.ufl.edu/research/sparse/umfpack */
/* -------------------------------------------------------------------------- */
/*
Realloc a block previously allocated by UMF_malloc.
Return NULL on failure (in which case the block is still allocated, and will
be kept at is present size). This routine is only used for Numeric->Memory.
*/
#include "umf_internal.h"
#if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG)
#include "umf_malloc.h"
#endif
GLOBAL void *UMF_realloc
(
void *p,
Int n_objects,
size_t size_of_object
)
{
size_t size ;
void *p2 ;
#ifdef UMF_TCOV_TEST
/* For exhaustive statement coverage testing only! */
/* Pretend to fail, to test out-of-memory conditions. */
umf_realloc_fail-- ;
if (umf_realloc_fail <= umf_realloc_hi &&
umf_realloc_fail >= umf_realloc_lo)
{
return ((void *) NULL) ;
}
#endif
/* make sure that we allocate something */
n_objects = MAX (1, n_objects) ;
size = (size_t) n_objects ;
ASSERT (size_of_object > 1) ;
if (size > Int_MAX / size_of_object)
{
/* :: int overflow in umf_realloc :: */
return ((void *) NULL) ;
}
size *= size_of_object ;
DEBUG0 (("UMF_realloc: "ID" n_objects "ID" size_of_object "ID"\n",
(Int) p, n_objects, (Int) size_of_object)) ;
/* see AMD/Source/amd_global.c for the memory allocator selection */
p2 = amd_realloc (p, size) ;
#if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG)
/* If p didn't exist on input, and p2 exists, then a new object has been
* allocated. */
if (p == (void *) NULL && p2 != (void *) NULL)
{
UMF_malloc_count++ ;
}
#endif
DEBUG0 (("UMF_realloc: "ID" new malloc count "ID"\n",
(Int) p2, UMF_malloc_count)) ;
return (p2) ;
}