Mercurial > octave-nkf
comparison liboctave/UMFPACK/UMFPACK/Source/umf_malloc.c @ 5164:57077d0ddc8e
[project @ 2005-02-25 19:55:24 by jwe]
author | jwe |
---|---|
date | Fri, 25 Feb 2005 19:55:28 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5163:9f3299378193 | 5164:57077d0ddc8e |
---|---|
1 /* ========================================================================== */ | |
2 /* === UMF_malloc =========================================================== */ | |
3 /* ========================================================================== */ | |
4 | |
5 /* -------------------------------------------------------------------------- */ | |
6 /* UMFPACK Version 4.4, Copyright (c) 2005 by Timothy A. Davis. CISE Dept, */ | |
7 /* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */ | |
8 /* web: http://www.cise.ufl.edu/research/sparse/umfpack */ | |
9 /* -------------------------------------------------------------------------- */ | |
10 | |
11 /* | |
12 Allocate a block of n objects, each of a given size. This routine does not | |
13 handle the case when the size is 1 (allocating char's) because of potential | |
14 integer overflow. UMFPACK never does that. | |
15 Also maintains the UMFPACK malloc count. | |
16 */ | |
17 | |
18 #include "umf_internal.h" | |
19 | |
20 #if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG) | |
21 | |
22 /* | |
23 UMF_malloc_count is a count of the objects malloc'd by UMFPACK. If you | |
24 suspect a memory leak in your program (caused by not properly destroying | |
25 the Symbolic and Numeric objects) then compile with -DUMF_MALLOC_COUNT and | |
26 check value of UMF_malloc_count. By default, UMF_MALLOC_COUNT is not | |
27 defined, and thus UMFPACK has no global variables. | |
28 */ | |
29 | |
30 GLOBAL Int UMF_malloc_count = 0 ; | |
31 | |
32 #endif | |
33 | |
34 #ifdef UMF_TCOV_TEST | |
35 /* For exhaustive statement coverage testing only! */ | |
36 GLOBAL int umf_fail, umf_fail_lo, umf_fail_hi ; | |
37 GLOBAL int umf_realloc_fail, umf_realloc_lo, umf_realloc_hi ; | |
38 #endif | |
39 | |
40 GLOBAL void *UMF_malloc | |
41 ( | |
42 Int n_objects, | |
43 size_t size_of_object | |
44 ) | |
45 { | |
46 size_t size ; | |
47 void *p ; | |
48 | |
49 #ifdef UMF_TCOV_TEST | |
50 /* For exhaustive statement coverage testing only! */ | |
51 /* Pretend to fail, to test out-of-memory conditions. */ | |
52 umf_fail-- ; | |
53 if (umf_fail <= umf_fail_hi && umf_fail >= umf_fail_lo) | |
54 { | |
55 DEBUG0 (("umf_malloc: Pretend to fail %d %d %d\n", | |
56 umf_fail, umf_fail_hi, umf_fail_lo)) ; | |
57 return ((void *) NULL) ; | |
58 } | |
59 #endif | |
60 | |
61 DEBUG0 (("UMF_malloc: ")) ; | |
62 | |
63 /* make sure that we allocate something */ | |
64 n_objects = MAX (1, n_objects) ; | |
65 | |
66 size = (size_t) n_objects ; | |
67 ASSERT (size_of_object > 1) ; | |
68 if (size > Int_MAX / size_of_object) | |
69 { | |
70 /* object is too big for integer pointer arithmetic */ | |
71 return ((void *) NULL) ; | |
72 } | |
73 size *= size_of_object ; | |
74 | |
75 /* see umf_config.h for the memory allocator selection */ | |
76 p = ALLOCATE (size) ; | |
77 | |
78 DEBUG0 ((ID"\n", (Int) p)) ; | |
79 | |
80 #if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG) | |
81 if (p) | |
82 { | |
83 /* One more object has been malloc'ed. Keep track of the count. */ | |
84 /* (purely for sanity checks). */ | |
85 UMF_malloc_count++ ; | |
86 DEBUG0 ((" successful, new malloc count: "ID"\n", UMF_malloc_count)) ; | |
87 } | |
88 #endif | |
89 | |
90 return (p) ; | |
91 } |