~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to Lib/sandbox/pysparse/umfpack/umf_malloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

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