1 //------------------------------------------------------------------------------
2 // SLIP_LU/SLIP_initialize_expert: intialize SLIP_LU memory functions for GMP
3 //------------------------------------------------------------------------------
4 
5 // SLIP_LU: (c) 2019-2020, Chris Lourenco, Jinhao Chen, Erick Moreno-Centeno,
6 // Timothy A. Davis, Texas A&M University.  All Rights Reserved.  See
7 // SLIP_LU/License for the license.
8 
9 //------------------------------------------------------------------------------
10 
11 // SLIP_initialize_expert initializes the working environment for SLIP_LU with
12 // custom memory functions that are used for SLIP_LU and GMP.
13 
14 // The four inputs to this function are pointers to four functions with the
15 // same signatures as the ANSI C malloc, calloc, realloc, and free functions.
16 // That is:
17 
18 //     #include <stdlib.h>
19 //     void *malloc (size_t size) ;
20 //     void *calloc (size_t nmemb, size_t size) ;
21 //     void *realloc (void *ptr, size_t size) ;
22 //     void free (void *ptr) ;
23 
24 #include "slip_internal.h"
25 
SLIP_initialize_expert(void * (* MyMalloc)(size_t),void * (* MyCalloc)(size_t,size_t),void * (* MyRealloc)(void *,size_t),void (* MyFree)(void *))26 SLIP_info SLIP_initialize_expert
27 (
28     void* (*MyMalloc) (size_t),             // user-defined malloc
29     void* (*MyCalloc) (size_t, size_t),     // user-defined calloc
30     void* (*MyRealloc) (void *, size_t),    // user-defined realloc
31     void  (*MyFree) (void *)                // user-defined free
32 )
33 {
34 
35     if (slip_initialized ( )) return (SLIP_PANIC) ;
36 
37     //--------------------------------------------------------------------------
38     // define the malloc/calloc/realloc/free functions
39     //--------------------------------------------------------------------------
40 
41     SuiteSparse_config.malloc_func  = MyMalloc ;
42     SuiteSparse_config.calloc_func  = MyCalloc ;
43     SuiteSparse_config.realloc_func = MyRealloc ;
44     SuiteSparse_config.free_func    = MyFree ;
45 
46     //--------------------------------------------------------------------------
47     // Set GMP memory functions
48     //--------------------------------------------------------------------------
49 
50     return (SLIP_initialize ( )) ;
51 }
52 
53