[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #49010] mxSetDimensions for cell arrays
From: |
Guillaume |
Subject: |
[Octave-bug-tracker] [bug #49010] mxSetDimensions for cell arrays |
Date: |
Mon, 5 Sep 2016 16:21:00 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0 |
URL:
<http://savannah.gnu.org/bugs/?49010>
Summary: mxSetDimensions for cell arrays
Project: GNU Octave
Submitted by: gyom
Submitted on: Mon 05 Sep 2016 04:20:58 PM GMT
Category: Libraries
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Crash
Status: None
Assigned to: None
Originator Name: Guillaume
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: dev
Operating System: GNU/Linux
_______________________________________________________
Details:
There seems to be an issue if the new dimensions array passed to
mxSetDimensions is freed explicitly when called on a cell array. The following
piece of code illustrates the problem by trying to reshape an array with two
elements in a 1x2 array:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray **mx;
mwSize *dim = NULL;
mx = (mxArray **)prhs;
mexCallMATLAB(0, NULL, 1, mx, "disp");
/* assume first input argument has two elements */
dim = mxMalloc(2 * sizeof(*dim));
dim[0] = 1; dim[1] = 2;
mxSetDimensions(mx[0], dim, 2);
mxFree(dim);
mexCallMATLAB(0, NULL, 1, mx, "disp");
}
octave:1> test_mexCallMATLAB2([1;2])
1
2
1 2
octave:2> test_mexCallMATLAB2({1;2})
panic: Segmentation fault -- stopping myself...
{
[1,1] = 1
[2,1] = 2
}
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Segmentation fault
The segfault disappears if the line "mxFree(dim);" is removed. It works as
expected in MATLAB. I assume it is valid to free the dimensions array as
mxSetDimensions makes a copy of it, if I understand the documentation right:
http://www.mathworks.com/help/matlab/apiref/mxsetdimensions.html
"mxSetDimensions allocates heap space to hold the input size array."
It works for numeric and struct arrays, but not cell arrays.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?49010>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #49010] mxSetDimensions for cell arrays,
Guillaume <=