help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C mex interface mxSetPr


From: louisranjard
Subject: C mex interface mxSetPr
Date: Thu, 6 Dec 2007 19:17:48 -0800 (PST)

Hi there,

I have a question relative to a C mex function.
I've written a C mex function which works properly with matlab (and octave)
on my machine but crashes on other machines with octave (don't know about
matlab).
Basically, what happens is that it compiles ok (with mex in octave), run
fine once and then any more command produce a crash of octave which exits
with a segmentation fault.
I checked this function with valgrind and it looks ok so I think it comes
from the mex interface.

The function returns a pointer on a matrix dynamically allocated. Here is
schematically the part of the function which I think produces the problem
(part of mexFunction):

double *mata;
plhs[1] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL);
mata = function(); # returns a ptr declared with mxMalloc in the function
mxSetPr(plhs[1],mata); 
mxSetM(plhs[1],N); 
mxSetN(plhs[1],M);

Interestingly if I free the pointer mata (adding mxFree(mata) ) it doesn't
crash but I loose the first value of the returned matrix.

I don't understand why it's working on my machine (fedora 6, 64bits, octave
2.9.9) and not others (32 or 64bits, fedoras, octave 2.9.15).

Does anyone have any idea of what I'm doing wrong or what is going on????
Where should I look for???
Should I rather write the function using DEFUN_DLD?? (any tips for doing
that??? Would it be faster by the way??)

Any help would be much appreciated!!
thanks,
Louis

-- 
View this message in context: 
http://www.nabble.com/C-mex-interface-mxSetPr-tf4959819.html#a14205392
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]