Mercurial > octave
diff liboctave/util/oct-sparse.cc @ 23391:209e749363a2
safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
* oct-sparse.cc: New file.
* liboctave/util/module.mk: Update.
* oct-sparse.h, oct-sparse.cc (octave::suitesparse_integer): New typedef.
(octave::to_suitesparse_intptr, octave::to_octave_idx_type_ptr):
New functions.
* amd.cc, ccolamd.cc, colamd.cc, dmperm.cc, symbfact.cc, CSparse.cc,
dSparse.cc, sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc: Use new
functions and typedef to avoid conflicts between pointers to
octave_idx_type and SuiteSparse_long on systems where they are
equivalent types but have incompatible definitions (long long int *
vs. long int *, for example, when both are 64-bits wide).
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 12 Apr 2017 16:29:50 -0400 |
parents | |
children | 194eb4bd202b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/util/oct-sparse.cc Wed Apr 12 16:29:50 2017 -0400 @@ -0,0 +1,80 @@ +/* + +Copyright (C) 2017 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "lo-error.h" +#include "oct-sparse.h" + +#if (defined (HAVE_AMD) || defined (HAVE_CCOLAMD) \ + || defined (HAVE_CHOLMOD) || defined (HAVE_COLAMD) \ + || defined (HAVE_CXSPARSE) || defined (HAVE_UMFPACK)) + +static inline void +check_suitesparse_integer_size (void) +{ + // FIXME: maybe it would be better to make this a configure check and + // disable suitesparse if it fails? + + if (sizeof (octave::suitesparse_integer) != sizeof (octave_idx_type)) + (*current_liboctave_error_handler) + ("size of suitesparse integer does not match octave_idx_type!"); +} + +namespace octave +{ + suitesparse_integer * + to_suitesparse_intptr (octave_idx_type *i) + { + check_suitesparse_integer_size (); + + return reinterpret_cast<suitesparse_integer *> (i); + } + + const suitesparse_integer * + to_suitesparse_intptr (const octave_idx_type *i) + { + check_suitesparse_integer_size (); + + return reinterpret_cast<const suitesparse_integer *> (i); + } + + octave_idx_type* + to_octave_idx_type_ptr (suitesparse_integer *i) + { + check_suitesparse_integer_size (); + + return reinterpret_cast<octave_idx_type *> (i); + } + + const octave_idx_type* + to_octave_idx_type_ptr (const suitesparse_integer *i) + { + check_suitesparse_integer_size (); + + return reinterpret_cast<const octave_idx_type *> (i); + } +} + +#endif