| SPEIGS 1.0.0

mex.h
1/* Published header for libmex, the mex library.
2 Copyright 1984-2018 The MathWorks, Inc.
3 This file containes types, macros, and declarations necessary to
4 interface mex files with the current version of MATLAB.
5
6 See the release notes for information on supporting earlier versions. */
7
8#if defined(_MSC_VER)
9# pragma once
10#endif
11#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))
12# pragma once
13#endif
14
15#ifndef mex_h
16#define mex_h
17
18#ifdef __cplusplus
19# define LIBMWMEX_API_EXTERN_C extern "C"
20#else
21# define LIBMWMEX_API_EXTERN_C extern
22#endif
23
24#ifdef _MSC_VER
25# define MWMEX_EXPORT_SYM __declspec(dllexport)
26#elif __GNUC__ >= 4
27# define MWMEX_EXPORT_SYM __attribute__ ((visibility("default")))
28#else
29# define MWMEX_EXPORT_SYM
30#endif
31
32#ifdef MW_NEEDS_VERSION_H
33# define MEXFUNCTION_LINKAGE LIBMWMEX_API_EXTERN_C MWMEX_EXPORT_SYM
34#else
35# define MEXFUNCTION_LINKAGE LIBMWMEX_API_EXTERN_C
36#endif
37
38#include <stdio.h>
39
40
41 typedef struct impl_info_tag *MEX_impl_info;
42
43#include "matrix.h"
44
45#ifdef __cplusplus
46 extern "C"
47{
48#endif
49 typedef void (*mex_exit_fn)(void);
50#ifdef __cplusplus
51}
52#endif
53
54 typedef struct mexGlobalTableEntry_Tag
55{
56 const char *name; /* The name of the global */
57 mxArray **variable; /* A pointer to the variable */
58} mexGlobalTableEntry, *mexGlobalTable;
59
60#ifdef _WIN32
61#define cicompare(s1,s2) utStrcmpi((s1),(s2))
62#else
63#define cicompare(s1,s2) strcmp((s1),(s2))
64#endif
65#define cscompare(s1,s2) strcmp((s1),(s2))
66
67 typedef struct mexFunctionTableEntry_tag {
68 const char * name;
69 mxFunctionPtr f;
70 int nargin;
71 int nargout;
72 struct _mexLocalFunctionTable *local_function_table;
73} mexFunctionTableEntry, *mexFunctionTable;
74
75 typedef struct _mexLocalFunctionTable {
76 size_t length;
77 mexFunctionTable entries;
78} _mexLocalFunctionTable, *mexLocalFunctionTable;
79
80 typedef struct {
81 void (*initialize)(void);
82 void (*terminate)(void);
83} _mexInitTermTableEntry, *mexInitTermTableEntry;
84
85#define MEX_INFORMATION_VERSION 1
86
87 typedef void (*fn_clean_up_after_error)(void);
88 typedef const char *(*fn_simple_function_to_string)(mxFunctionPtr f);
89
90 typedef mexLocalFunctionTable (*fn_mex_get_local_function_table)(void);
91 typedef mexLocalFunctionTable (*fn_mex_set_local_function_table)(mexLocalFunctionTable);
92
93
94#if defined(TARGET_API_VERSION)
95#if !(TARGET_API_VERSION == 700 || TARGET_API_VERSION == 800)
96#error invalid TARGET_VERSION_API definition
97#elif defined(MEX_DOUBLE_HANDLE) && TARGET_API_VERSION != 700
98#error It is illegal to use MEX_DOUBLE_HANDLE with linear versioning
99#elif defined(MX_COMPAT_32) && TARGET_API_VERSION != 700
100#error It is illegal to use MX_COMPAT_32 with linear versioning
101#endif
102#endif
103
104
105#if !defined(TARGET_API_VERSION) || TARGET_API_VERSION == 700
106#ifndef MEX_DOUBLE_HANDLE
107#define mexCallMATLAB mexCallMATLABWithObject
108#define mexCallMATLABWithTrap mexCallMATLABWithTrapWithObject
109#define mexGetVariable mexGetVariableWithObject
110#define mexGet(a,b) \
111 NULL;do{mexGetIsDeprecated x;}while(0)
112#define mexSet(a,b,c) \
113 0;do{mexSetIsDeprecated x;}while(0)
114#endif /* MEX_DOUBLE_HANDLE */
115#define mexSetTrapFlag(a) \
116 0;do{mexSetTrapFlagIsDeprecated x;}while(0)
117
118
119#elif TARGET_API_VERSION == 800
120
121#define mexCallMATLAB mexCallMATLAB_800
122#define mexCallMATLABWithTrap mexCallMATLABWithTrap_800
123#define mexEvalString mexEvalString_800
124#define mexEvalStringWithTrap mexEvalStringWithTrap_800
125#define mexGet mexGetIsDeprecated
126#define mexSet mexSetIsDeprecated
127#define mexGetVariable mexGetVariable_800
128#define mexGetVariablePtr mexGetVariablePtr_800
129#define mexPutVariable mexPutVariable_800
130#define mexPrintf mexPrintf_800
131#define mexSetTrapFlag mexSetTrapFlagIsDeprecated
132#define mexErrMsgIdAndTxt mexErrMsgIdAndTxt_800
133#define mexWarnMsgIdAndTxt mexWarnMsgIdAndTxt_800
134#define mexErrMsgTxt mexErrMsgTxt_800
135#define mexWarnMsgTxt mexWarnMsgTxt_800
136#define mexIsLocked mexIsLocked_800
137#define mexLock mexLock_800
138#define mexUnlock mexUnlock_800
139#define mexMakeArrayPersistent mexMakeArrayPersistent_800
140#define mexMakeMemoryPersistent mexMakeMemoryPersistent_800
141#define mexPrintAssertion mexPrintAssertion_800
142#define mexIsGlobal mexIsGlobal_800
143#define mexFunctionName mexFunctionName_800
144#define mexAtExit mexAtExit_800
145
146#endif /* TARGET_API_VERSION */
147/*
148 * Issue error message and return to MATLAB prompt
149 */
150LIBMWMEX_API_EXTERN_C void mexErrMsgTxt(
151 const char *error_msg /* string with error message */
152 );
153
154
155/*
156 * Issue formatted error message with corresponding error identifier and return to MATLAB
157 * prompt.
158 */
159LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(
160 const char * identifier, /* string with error message identifier */
161 const char * err_msg, /* string with error message printf-style format */
162 ... /* any additional arguments */
163 );
164
165
166/*
167 * Invoke an unidentified warning. Such warnings can only be affected by the M-code
168 * 'warning * all', since they have no specific identifier. See also mexWarnMsgIdAndTxt.
169 */
170LIBMWMEX_API_EXTERN_C void mexWarnMsgTxt(
171 const char *warn_msg /* string with warning message */
172 );
173
174
175/*
176 * Invoke a warning with message identifier 'identifier' and message derived from 'fmt' and
177 * subsequent arguments. The warning may either get printed as is (if it is set to 'on'), or
178 * not actually get printed (if set to 'off'). See 'help warning' in MATLAB for more
179 * details.
180 */
181LIBMWMEX_API_EXTERN_C void mexWarnMsgIdAndTxt(
182 const char * identifier, /* string with warning message identifer */
183 const char * warn_msg, /* string with warning message printf-style format */
184 ... /* any additional arguments */
185 );
186
187
188/*
189 * mex equivalent to MATLAB's "disp" function
190 */
191LIBMWMEX_API_EXTERN_C int mexPrintf(
192 const char *fmt, /* printf style format */
193 ... /* any additional arguments */
194 );
195
196
197#define printf mexPrintf
198
199
200/*
201 * Remove all components of an array plus the array header itself
202 * from MATLAB's memory allocation list. The array will now
203 * persist between calls to the mex function. To destroy this
204 * array, you will need to explicitly call mxDestroyArray().
205 */
206LIBMWMEX_API_EXTERN_C void mexMakeArrayPersistent(
207 mxArray *pa /* pointer to array */
208 );
209
210
211/*
212 * Remove memory previously allocated via mxCalloc from MATLAB's
213 * memory allocation list. To free this memory, you will need to
214 * explicitly call mxFree().
215 */
216LIBMWMEX_API_EXTERN_C void mexMakeMemoryPersistent(void *ptr);
217
218
219/*
220 * call MATLAB function
221 */
222LIBMWMEX_API_EXTERN_C int mexCallMATLAB(
223 int nlhs, /* number of expected outputs */
224 mxArray *plhs[], /* pointer array to outputs */
225 int nrhs, /* number of inputs */
226 mxArray *prhs[], /* pointer array to inputs */
227 const char *fcn_name /* name of function to execute */
228 );
229
230
231/*
232 * call MATLAB function with Trap
233 */
234LIBMWMEX_API_EXTERN_C mxArray *mexCallMATLABWithTrap(
235 int nlhs, /* number of expected outputs */
236 mxArray *plhs[], /* pointer array to outputs */
237 int nrhs, /* number of inputs */
238 mxArray *prhs[], /* pointer array to inputs */
239 const char *fcn_name /* name of function to execute */
240 );
241
242
243/*
244 * Print an assertion-style error message and return control to the
245 * MATLAB command line.
246 */
247LIBMWMEX_API_EXTERN_C void mexPrintAssertion(
248 const char *test,
249 const char *fname,
250 int linenum,
251 const char *message);
252
253
254/*
255 * This function is deprecated and always return false.
256 */
257LIBMWMEX_API_EXTERN_C bool mexIsGlobal(const mxArray *pA);
258
259
260/*
261 * Place a copy of the array value into the specified workspace with the
262 * specified name
263 */
264LIBMWMEX_API_EXTERN_C int mexPutVariable(
265 const char *workspace,
266 const char *name,
267 const mxArray *parray /* matrix to copy */
268 );
269
270
271/*
272 * return a pointer to the array value with the specified variable
273 * name in the specified workspace
274 */
275LIBMWMEX_API_EXTERN_C const mxArray *mexGetVariablePtr(
276 const char *workspace,
277 const char *name /* name of symbol */
278 );
279
280
281/*
282 * return a copy of the array value with the specified variable
283 * name in the specified workspace
284 */
285LIBMWMEX_API_EXTERN_C mxArray *mexGetVariable(
286 const char *workspace,
287 const char *name /* name of variable in question */
288 );
289
290
291/*
292 * Lock a MEX-function so that it cannot be cleared from memory.
293 */
294LIBMWMEX_API_EXTERN_C void mexLock(void);
295
296
297/*
298 * Unlock a locked MEX-function so that it can be cleared from memory.
299 */
300LIBMWMEX_API_EXTERN_C void mexUnlock(void);
301
302
303/*
304 * Return true if the MEX-function is currently locked, false otherwise.
305 */
306LIBMWMEX_API_EXTERN_C bool mexIsLocked(void);
307
308
309/*
310 * Return the name of a the MEXfunction currently executing.
311 */
312LIBMWMEX_API_EXTERN_C const char *mexFunctionName(void);
313
314
315/*
316 * Parse and execute MATLAB syntax in string. Returns zero if successful,
317 * and a non zero value if an error occurs.
318 */
319LIBMWMEX_API_EXTERN_C int mexEvalString(
320 const char *str /* matlab command string */
321 );
322
323
324/*
325 * Parse and execute MATLAB syntax in string. Returns NULL if successful,
326 * and an MException if an error occurs.
327 */
328LIBMWMEX_API_EXTERN_C mxArray* mexEvalStringWithTrap(
329 const char *str /* matlab command string */
330 );
331
332
333/*
334 * Register Mex-file's At-Exit function (accessed via MEX callback)
335 */
336LIBMWMEX_API_EXTERN_C int mexAtExit(mex_exit_fn exit_fcn);
337#ifdef MEX_DOUBLE_HANDLE
338
339/* API interface which mimics the "get" function */
340LIBMWMEX_API_EXTERN_C const mxArray *mexGet(double handle, const char *property);
341
342
343/*
344 * mex equivalent to MATLAB's "set" function
345 */
346LIBMWMEX_API_EXTERN_C int mexSet(double handle, const char *property, mxArray *value);
347
348#endif
349
350
351MEXFUNCTION_LINKAGE
352/*
353 * mexFunction is the user-defined C routine that is called upon invocation
354 * of a MEX-function.
355 */
356 void mexFunction(
357 int nlhs, /* number of expected outputs */
358 mxArray *plhs[], /* array of pointers to output arguments */
359 int nrhs, /* number of inputs */
360 const mxArray *prhs[] /* array of pointers to input arguments */
361 );
362
363#endif /* mex_h */
mexFunction
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Matlab entry function.
Definition: mex_speigs.c:47
_mexInitTermTableEntry
Definition: mex.h:80
_mexLocalFunctionTable
Definition: mex.h:75
mexFunctionTableEntry_tag
Definition: mex.h:67
mexGlobalTableEntry_Tag
Definition: mex.h:55