From 4f1e5e1bc27a55028b8e6e7b383d696e2db96742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 22 Sep 2023 13:28:13 +0200 Subject: [PATCH] MS-SBVAR MEX: fixes related to C linkage (extern "C") MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix or remove various #ifdefs, and remove unused “int constant_seed”. --- mex/sources/ms-sbvar/modify_for_mex.cc | 23 ++++----------- mex/sources/ms-sbvar/modify_for_mex.h | 41 ++++++++++++++------------ 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/mex/sources/ms-sbvar/modify_for_mex.cc b/mex/sources/ms-sbvar/modify_for_mex.cc index 2e32ae40a..52206e073 100644 --- a/mex/sources/ms-sbvar/modify_for_mex.cc +++ b/mex/sources/ms-sbvar/modify_for_mex.cc @@ -17,25 +17,12 @@ * along with Dynare. If not, see . */ -#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE) +#include -# include - -# ifdef __cplusplus extern "C" +[[noreturn]] +void +msExit([[maybe_unused]] int status) { -# endif - - int constant_seed; - - [[noreturn]] - void - msExit([[maybe_unused]] int status) - { - throw "Error in MS-SBVAR MEX file.\n"; - } - -# ifdef __cplusplus + throw "Error in MS-SBVAR MEX file.\n"; } -# endif -#endif diff --git a/mex/sources/ms-sbvar/modify_for_mex.h b/mex/sources/ms-sbvar/modify_for_mex.h index 973fa425f..3fcb78b4d 100644 --- a/mex/sources/ms-sbvar/modify_for_mex.h +++ b/mex/sources/ms-sbvar/modify_for_mex.h @@ -17,28 +17,34 @@ * along with Dynare. If not, see . */ -#ifndef _MEXMOD -#define _MEXMOD +#ifndef _MODIFY_FOR_MEX_H +#define _MODIFY_FOR_MEX_H -#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE) +#include +#include +#include -# include -# include -# include - -# define dw_malloc mxMalloc -# define dw_calloc mxCalloc -# define dw_realloc mxRealloc -# define dw_free mxFree -# define dw_exit msExit +#define dw_malloc mxMalloc +#define dw_calloc mxCalloc +#define dw_realloc mxRealloc +#define dw_free mxFree +#define dw_exit msExit /* Handle Ctrl-C in Matlab/Octave */ -# ifdef MATLAB_MEX_FILE -extern bool utIsInterruptPending(); +#ifdef MATLAB_MEX_FILE +# ifdef __cplusplus +extern "C" # else -# include +extern # endif +bool utIsInterruptPending(); +#else +# include +#endif +#ifdef __cplusplus +extern "C" +#endif // NB: C23 has the [[noreturn]] attribute, so this #ifdef can be removed when // we upgrade #ifdef __cplusplus @@ -48,7 +54,4 @@ _Noreturn #endif void msExit(int status); -extern int constant_seed; - -#endif -#endif +#endif // _MODIFY_FOR_MEX_H