[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #31706] mxDuplicateArray sometimes references
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #31706] mxDuplicateArray sometimes references (not: copies) the input data |
Date: |
Fri, 19 Nov 2010 11:47:41 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 |
URL:
<http://savannah.gnu.org/bugs/?31706>
Summary: mxDuplicateArray sometimes references (not: copies)
the input data
Project: GNU Octave
Submitted by: None
Submitted on: Fr 19 Nov 2010 11:47:40 UTC
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name: Andreas Zoellner
Originator Email: address@hidden
Open/Closed: Open
Discussion Lock: Any
Release: 3.2.4
Operating System: Microsoft Windows
_______________________________________________________
Details:
For some inputs, the MEX function mxDuplicateArray only creates a reference
to, not a deep copy of, the input data.
Consider the following file "bug.cpp":
#include "mex.h"
#define X prhs[0]
#define Y plhs[0]
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs < 1) mexErrMsgTxt("One input argument required.");
Y = mxDuplicateArray(X);
double*const x = mxGetPr(X);
double*const y = mxGetPr(Y);
mexPrintf("mxArray: %x and %x\n", (int)X, (int)Y);
mexPrintf("mxGetPr: %x and %x\n", (int)x, (int)y);
if (x == y) mexWarnMsgTxt("Created only a reference, not a copy!");
for (unsigned int i = 0; i < mxGetNumberOfElements(Y); ++i) y[i] = 1;
}
>> mex bug.cpp; x=1:3; y=bug(x); x, y
works as expected (x = [1 2 3]; y = [1 1 1];), but
>> mex bug.cpp; x = linspace(1,3,3); x, y
fails, overwriting the input (x = [1 1 1]; y = [1 1 1];)
Maybe this has something to do with lazy copying by data sharing?
----
Octave Version 3.2.4, official binary from Octave Forge
(http://sourceforge.net/projects/octave/files/Octave_Windows%20-%20MinGW/Octave%203.2.4%20for%20Windows%20MinGW32%20Installer/Octave-3.2.4_i686-pc-mingw32_gcc-4.4.0_setup.exe)
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?31706>
_______________________________________________
Nachricht geschickt von/durch Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #31706] mxDuplicateArray sometimes references (not: copies) the input data,
anonymous <=