Skip to content

Commit

Permalink
CXSparse: now using SuiteSparse_config_malloc/calloc/realloc/free
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Feb 6, 2024
1 parent 15a8139 commit 3e43bff
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions CXSparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cmake_minimum_required ( VERSION 3.22 )

set ( CXSPARSE_DATE "Feb XX, 2024" ) # FIXME for 7.7.0
set ( CXSPARSE_VERSION_MAJOR 4 CACHE STRING "" FORCE )
set ( CXSPARSE_VERSION_MINOR 3 CACHE STRING "" FORCE )
set ( CXSPARSE_VERSION_SUB 2 CACHE STRING "" FORCE )
set ( CXSPARSE_VERSION_MINOR 4 CACHE STRING "" FORCE )
set ( CXSPARSE_VERSION_SUB 0 CACHE STRING "" FORCE )

message ( STATUS "Building CXSparse version: v"
${CXSPARSE_VERSION_MAJOR}.
Expand Down
5 changes: 4 additions & 1 deletion CXSparse/Doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Feb XX, 2024: version 4.3.2
Feb XX, 2024: version 4.4.0

* minor updates to build system
* revise malloc/calloc/realloc/free wrappers: now relying on
SuiteSparse_config functions, which normally default to malloc/etc,
except when inside MATLAB when they are mxMalloc/etc.

Jan 10, 2024: version 4.3.1

Expand Down
8 changes: 4 additions & 4 deletions CXSparse/Include/cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
#endif

#define CS_VER 4 /* CXSparse Version */
#define CS_SUBVER 3
#define CS_SUBSUB 2
#define CS_SUBVER 4
#define CS_SUBSUB 0
#define CS_DATE "Feb XX, 2024" /* CXSparse release date */
#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2024"
#define CXSPARSE

#include "SuiteSparse_config.h"

#define CXSPARSE__VERSION SUITESPARSE__VERCODE(4,3,2)
#define CXSPARSE__VERSION SUITESPARSE__VERCODE(4,4,0)
#if !defined (SUITESPARSE__VERSION) || \
(SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,7,0))
#error "CXSparse 4.3.2 requires SuiteSparse_config 7.7.0 or later"
#error "CXSparse 4.4.0 requires SuiteSparse_config 7.7.0 or later"
#endif

#define cs_long_t int64_t
Expand Down
10 changes: 9 additions & 1 deletion CXSparse/MATLAB/CSparse/private/cs_make_helper.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@
srcdir = '../../Source/' ;
hfile = '../../Include/cs.h' ;

% compile SuiteSparse_config.c
[anysrc timestamp kk] = compile_source ('../../../SuiteSparse_config/', ...
'SuiteSparse_config', obj, hfile, force, mexcmd, kk, details) ;
CS = ['SuiteSparse_config' obj] ;
if (nargout > 0)
objfiles = ['../CSparse/SuiteSparse_config' obj] ;
end

% compile each CSparse source file
[anysrc timestamp kk] = compile_source ('', 'cs_mex', obj, hfile, force, ...
mexcmd, kk, details) ;
CS = ['cs_mex' obj] ;
CS = [CS ' cs_mex' obj] ;
if (nargout > 0)
objfiles = ['../CSparse/cs_mex' obj] ;
end
Expand Down
19 changes: 9 additions & 10 deletions CXSparse/Source/cs_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
// CXSparse, Copyright (c) 2006-2022, Timothy A. Davis. All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
#include "cs.h"
#ifdef MATLAB_MEX_FILE
#define malloc mxMalloc
#define free mxFree
#define realloc mxRealloc
#define calloc mxCalloc
#endif

/* wrapper for malloc */
void *cs_malloc (CS_INT n, size_t size)
{
return (malloc (CS_MAX (n,1) * size)) ;
return (SuiteSparse_config_malloc (CS_MAX (n,1) * size)) ;
}

/* wrapper for calloc */
void *cs_calloc (CS_INT n, size_t size)
{
return (calloc (CS_MAX (n,1), size)) ;
return (SuiteSparse_config_calloc (CS_MAX (n,1), size)) ;
}

/* wrapper for free */
void *cs_free (void *p)
{
if (p) free (p) ; /* free p if it is not already NULL */
if (p)
{
/* free p if it is not already NULL */
SuiteSparse_config_free (p) ;
}
return (NULL) ; /* return NULL to simplify the use of cs_free */
}

/* wrapper for realloc */
void *cs_realloc (void *p, CS_INT n, size_t size, CS_INT *ok)
{
void *pnew ;
pnew = realloc (p, CS_MAX (n,1) * size) ; /* realloc the block */
/* realloc the block */
pnew = SuiteSparse_config_realloc (p, CS_MAX (n,1) * size) ;
*ok = (pnew != NULL) ; /* realloc fails if pnew is NULL */
return ((*ok) ? pnew : p) ; /* return original p if failure */
}
2 changes: 1 addition & 1 deletion Example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ find_package ( CAMD 3.3.2 REQUIRED )
find_package ( CCOLAMD 3.3.3 REQUIRED )
find_package ( CHOLMOD 5.2.1 REQUIRED )
find_package ( COLAMD 3.3.3 REQUIRED )
find_package ( CXSparse 4.3.2 REQUIRED )
find_package ( CXSparse 4.4.0 REQUIRED )
find_package ( GraphBLAS 9.1.0 )
find_package ( KLU 2.3.3 REQUIRED )
find_package ( KLU_CHOLMOD 2.3.3 REQUIRED )
Expand Down

0 comments on commit 3e43bff

Please sign in to comment.