From a8ca62dc435590ee9bc67b81106f35c51824af72 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Fri, 27 Feb 2015 22:09:12 -0500 Subject: [PATCH] Check CHOLMOD version at runtime --- base/sparse/cholmod.jl | 29 +++++++++++++++++++++++++++-- base/sparse/cholmod_h.jl | 9 --------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index a98d008daa4532..415d1b18532b0a 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -27,7 +27,7 @@ macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == SuiteSparse_long ? "l for Ti in IndexTypes @eval begin function common(::Type{$Ti}) - a = fill(0xff, cholmod_com_sz) + a = fill(0xff, common_size) @isok ccall((@cholmod_name "start" $Ti , :libcholmod), Cint, (Ptr{UInt8},), a) set_print_level(a, 0) # no printing from CHOLMOD by default @@ -36,16 +36,41 @@ for Ti in IndexTypes end end +const version_array = Array(Cint, 3) +if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL + ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array) +else + ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array) +end +const version = VersionNumber(version_array...) + ### These offsets are defined in SuiteSparse_wrapper.c +const common_size = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,()) + const cholmod_com_offsets = Array(Csize_t, 19) ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper), - Void, (Ptr{Csize_t},), cholmod_com_offsets) + Void, (Ptr{Csize_t},), cholmod_com_offsets) + const common_supernodal = (1:4) + cholmod_com_offsets[4] const common_final_ll = (1:4) + cholmod_com_offsets[7] const common_print = (1:4) + cholmod_com_offsets[13] const common_itype = (1:4) + cholmod_com_offsets[18] const common_dtype = (1:4) + cholmod_com_offsets[19] +function __init__() + println("Hej") + if dlsym(dlopen("libcholmod"), :cholmod_version) == C_NULL + throw(CHOLMODException("your version of CHOLMOD is old. It might not work correctly with Julia. Please upgrade to a more recent version.")) + else + tmp = Array(Cint, 3) + ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array) + ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp) + if tmp != version_array + throw(CHOLMODException("your version of CHOLMOD differs from the version used when Julia was build. These versions must match.")) + end + end +end + function set_print_level(cm::Array{UInt8}, lev::Integer) cm[common_print] = reinterpret(UInt8, [int32(lev)]) end diff --git a/base/sparse/cholmod_h.jl b/base/sparse/cholmod_h.jl index f97dff5effd6ee..6dd972c5ea64ea 100644 --- a/base/sparse/cholmod_h.jl +++ b/base/sparse/cholmod_h.jl @@ -75,12 +75,3 @@ end macro isok(A) :($A == TRUE || throw(CHOLMODException(""))) end - -const version_array = Array(Cint, 3) -if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL - ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array) -else - ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array) -end -const version = VersionNumber(version_array...) -const cholmod_com_sz = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())