68 for (
mwSize i = 0; i < m; i++)
70 mwSize tmp = strlen (str[i]);
84 int nel = strlen (key);
90 for (
int i = 1; i < nel; i++)
92 if (! (isalnum (key[i]) || key[i] ==
'_'))
133 mwSize n = nsubs <= ndims ? nsubs : ndims;
138 retval = dims[n] * retval + subs[n];
321 else if (cn ==
"struct")
323 else if (cn ==
"logical")
325 else if (cn ==
"char")
327 else if (cn ==
"double")
329 else if (cn ==
"single")
331 else if (cn ==
"int8")
333 else if (cn ==
"uint8")
335 else if (cn ==
"int16")
337 else if (cn ==
"uint16")
339 else if (cn ==
"int32")
341 else if (cn ==
"uint32")
343 else if (cn ==
"int64")
345 else if (cn ==
"uint64")
347 else if (cn ==
"function_handle")
476 const char *p = tmp.
data ();
478 for (
mwIndex i = 0; i < nel; i++)
505 const char *p = tmp.
data ();
507 for (
mwIndex i = 0; i < nel; i++)
615 ndims (ndims_arg < 2 ? 2 : ndims_arg),
624 for (
mwIndex i = 0; i < ndims_arg; i++)
625 dims[i] = dims_arg[i];
644 for (
mwIndex i = ndims - 1; i > 1; i--)
715 && static_cast<mxLogical *> (
get_data ())[0] != 0);
777 default:
return "unknown";
961 for (
mwIndex i = 0; i < nd; i++)
978 error (
"invalid type for operation");
1022 double *dpr =
static_cast<double *
> (
pr);
1037 str ? (strlen (str) ? 1 : 0) : 0,
1038 str ? strlen (str) : 0),
1044 for (
mwIndex i = 0; i < nel; i++)
1060 for (
mwIndex j = 0; j < m; j++)
1062 const char *ptr = str[j];
1064 size_t tmp_len = strlen (ptr);
1066 for (
size_t i = 0; i < tmp_len; i++)
1067 cpr[m*i+j] = static_cast<mxChar> (ptr[i]);
1069 for (
size_t i = tmp_len; i < static_cast<size_t>(nc); i++)
1070 cpr[m*i+j] = static_cast<mxChar> (
' ');
1091 retval = *(
static_cast<bool *
> (
pr));
1095 retval = *(
static_cast<mxChar *
> (
pr));
1099 retval = *(
static_cast<float *
> (
pr));
1103 retval = *(
static_cast<double *
> (
pr));
1107 retval = *(
static_cast<int8_t *
> (
pr));
1111 retval = *(
static_cast<uint8_t *
> (
pr));
1115 retval = *(
static_cast<int16_t *
> (
pr));
1119 retval = *(
static_cast<uint16_t *
> (
pr));
1123 retval = *(
static_cast<int32_t *
> (
pr));
1127 retval = *(
static_cast<uint32_t *
> (
pr));
1131 retval = *(
static_cast<int64_t *
> (
pr));
1135 retval = *(
static_cast<uint64_t *
> (
pr));
1159 if (! (nel < buflen))
1170 for (
mwIndex i = 0; i < nel; i++)
1171 buf[i] = static_cast<char> (ptr[i]);
1191 for (
mwIndex i = 0; i < nel; i++)
1192 buf[i] = static_cast<char> (ptr[i]);
1209 retval = int_to_ov<mxLogical, boolNDArray, bool> (dv);
1222 for (
mwIndex i = 0; i < nel; i++)
1223 ptr[i] = static_cast<char> (ppr[i]);
1233 float *ppr =
static_cast<float *
> (
pr);
1241 float *ppi =
static_cast<float *
> (
pi);
1243 for (
mwIndex i = 0; i < nel; i++)
1254 for (
mwIndex i = 0; i < nel; i++)
1266 double *ppr =
static_cast<double *
> (
pr);
1274 double *ppi =
static_cast<double *
> (
pi);
1276 for (
mwIndex i = 0; i < nel; i++)
1277 ptr[i] =
Complex (ppr[i], ppi[i]);
1287 for (
mwIndex i = 0; i < nel; i++)
1296 retval = int_to_ov<int8_t, int8NDArray, octave_int8> (dv);
1300 retval = int_to_ov<uint8_t, uint8NDArray, octave_uint8> (dv);
1304 retval = int_to_ov<int16_t, int16NDArray, octave_int16> (dv);
1308 retval = int_to_ov<uint16_t, uint16NDArray, octave_uint16> (dv);
1312 retval = int_to_ov<int32_t, int32NDArray, octave_int32> (dv);
1316 retval = int_to_ov<uint32_t, uint32NDArray, octave_uint32> (dv);
1320 retval = int_to_ov<int64_t, int64NDArray, octave_int64> (dv);
1324 retval = int_to_ov<uint64_t, uint64NDArray, octave_uint64> (dv);
1336 template <
typename ELT_T,
typename ARRAY_T,
typename ARRAY_ELT_T>
1344 ELT_T *ppr =
static_cast<ELT_T *
> (
pr);
1347 error (
"complex integer types are not supported");
1352 ARRAY_ELT_T *ptr = val.fortran_vec ();
1354 for (
mwIndex i = 0; i < nel; i++)
1373 memcpy (
pr, val.
pr, nbytes);
1376 memcpy (
pi, val.
pi, nbytes);
1449 bool *ppr =
static_cast<bool *
> (
pr);
1452 static_cast<octave_idx_type> (
nzmax));
1456 val.
xdata (i) = ppr[i];
1468 error (
"single precision sparse data type not supported");
1475 double *ppr =
static_cast<double *
> (
pr);
1476 double *ppi =
static_cast<double *
> (
pi);
1479 static_cast<octave_idx_type> (
nzmax));
1494 double *ppr =
static_cast<double *
> (
pr);
1497 static_cast<octave_idx_type> (
nzmax));
1501 val.
xdata (i) = ppr[i];
1539 memcpy (
pr, val.
pr, nbytes);
1542 memcpy (
pi, val.
pi, nbytes);
1600 for (
int i = 0; i <
nfields; i++)
1608 for (
int i = 0; i <
nfields; i++)
1615 for (
mwIndex i = 0; i < ntot; i++)
1629 fields =
static_cast<char **
>
1641 new_data =
static_cast<mxArray **
>
1650 for (
mwIndex i = 0; i < ntot; i++)
1658 new_data[j++] =
data[k++];
1675 if (key_num >= 0 && key_num <
nfields)
1681 int new_nfields =
nfields - 1;
1683 char **new_fields =
static_cast<char **
>
1690 for (
int i = 0; i < key_num; i++)
1691 new_fields[i] =
fields[i];
1693 for (
int i = key_num + 1; i <
nfields; i++)
1694 new_fields[i-1] =
fields[i];
1696 if (new_nfields > 0)
1702 for (
mwIndex i = 0; i < ntot; i++)
1707 new_data[j++] =
data[k++];
1714 nfields = new_nfields;
1726 return key_num >= 0 && key_num <
nfields
1736 return key_num >= 0 && key_num <
nfields ?
fields[key_num] : 0;
1743 for (
int i = 0; i <
nfields; i++)
1745 if (! strcmp (key,
fields[i]))
1769 for (
int i = 0; i <
nfields; i++)
1796 * sizeof (
char *)))),
1801 for (
int i = 0; i <
nfields; i++)
1809 data[i] = ptr ? ptr->
dup () : 0;
1846 for (
mwIndex i = 0; i < nel; i++)
1873 for (
mwIndex i = 0; i < nel; i++)
1890 for (
mwIndex i = 0; i < nel; i++)
1893 data[i] = ptr ? ptr->
dup () : 0;
1936 : rep (new
mxArray_struct (ndims, dims, num_keys, keys)), name (0) { }
2028 std::string nm = fcn->
name ();
2044 for (std::set<void *>::iterator p = context->
memlist.begin ();
2045 p != context->
memlist.end (); p++)
2051 for (std::set<mxArray *>::iterator p = context->
arraylist.begin ();
2067 error (
"%s: failed to allocate %d bytes of memory",
2093 memset (ptr, 0, n*t);
2119 std::set<void *>::iterator p =
memlist.find (ptr);
2164 warning (
"mxFree: skipping memory not allocated by mxMalloc, mxCalloc, or mxRealloc");
2185 std::set<void *>::iterator p =
memlist.find (ptr);
2203 std::set<mxArray *>::iterator p =
arraylist.find (ptr);
2244 bool inlist =
false;
2246 std::set<mxArray *>::iterator p =
arraylist.find (ptr);
2256 warning (
"mex::free_value: skipping memory not allocated by mex::make_value");
2347 static inline void *
2365 static inline void *
2369 mex_context->
unmark (ptr);
2377 if (key_num >= 0 && key_num <
nfields)
2415 return std::numeric_limits<double>::epsilon ();
2434 return mex_context ? mex_context->
calloc (n, size) : ::calloc (n, size);
2440 return mex_context ? mex_context->
malloc (n) : gnulib::malloc (n);
2446 return mex_context ? mex_context->
realloc (ptr, size)
2447 : gnulib::realloc (ptr, size);
2454 mex_context->
free (ptr);
2462 return mex_context ? mex_context->
mark_array (ptr) : ptr;
2576 if (! (mex_context && mex_context->
free_value (ptr)))
2729 return ptr->
get_m ();
2735 return ptr->
get_n ();
2781 return static_cast<double *
> (ptr->
get_data ());
3008 volatile int nargout = nargout_arg;
3010 int nargin = args.
length ();
3012 for (
int i = 0; i < nargin; i++)
3015 int nout = nargout == 0 ? 1 : nargout;
3017 for (
int i = 0; i < nout; i++)
3029 for (
int i = 0; i < nargin; i++)
3032 if (setjmp (context.
jump) == 0)
3040 int tmp_nargout = nargout;
3041 int tmp_nargin = nargin;
3043 fcn (tmp_nargout, argout, tmp_nargin, argin);
3049 fcn (nargout, argout, nargin, argin);
3059 if (nargout == 0 && argout[0])
3067 for (
int i = 0; i < nargout; i++)
3082 return mex_context ? mex_context->
function_name () :
"unknown";
3087 mxArray *argin[],
const char *fname)
3099 for (
int i = 0; i < nargin; i++)
3115 mex_context->
abort ();
3118 int num_to_copy = retval.
length ();
3120 if (nargout < retval.
length ())
3121 num_to_copy = nargout;
3123 for (
int i = 0; i < num_to_copy; i++)
3129 argout[i] = mex_context->
make_value (retval (i));
3132 while (num_to_copy < nargout)
3133 argout[num_to_copy++] = 0;
3175 if (s && strlen (s) > 0)
3184 mex_context->
abort ();
3190 if (fmt && strlen (fmt) > 0)
3193 size_t len = strlen (fname) + 2 + strlen (fmt) + 1;
3195 sprintf (tmpfmt,
"%s: %s", fname, fmt);
3197 va_start (args, fmt);
3208 mex_context->
abort ();
3223 if (fmt && strlen (fmt) > 0)
3226 size_t len = strlen (fname) + 2 + strlen (fmt) + 1;
3228 sprintf (tmpfmt,
"%s: %s", fname, fmt);
3230 va_start (args, fmt);
3241 va_start (args, fmt);
3254 if (! strcmp (space,
"global"))
3262 bool caller = ! strcmp (space,
"caller");
3263 bool base = ! strcmp (space,
"base");
3283 mexErrMsgTxt (
"mexGetVariable: symbol table does not exist");
3311 if (name[0] ==
'\0')
3314 if (! name || name[0] ==
'\0')
3317 if (! strcmp (space,
"global"))
3325 bool caller = ! strcmp (space,
"caller");
3326 bool base = ! strcmp (space,
"base");
3346 mexErrMsgTxt (
"mexPutVariable: symbol table does not exist");
3371 assert (curr_mex_fcn);
3420 if (mex_lock_count.find (fname) == mex_lock_count.end ())
3421 mex_lock_count[fname] = 1;
3423 mex_lock_count[fname]++;
3435 return (ret ? 0 : 1);
3445 std::map<std::string,int>::iterator p = mex_lock_count.find (fname);
3447 if (p != mex_lock_count.end ())
3449 int count = --mex_lock_count[fname];
3455 mex_lock_count.erase (p);