help-octave
[Top][All Lists]
Advanced

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

Re: C mex interface mxSetPr


From: David Bateman
Subject: Re: C mex interface mxSetPr
Date: Fri, 07 Dec 2007 10:12:43 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

louisranjard wrote:
> 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
>
>   
The change

2007-11-14 David Bateman <address@hidden>

* mex.cc (mxSetDimensions, mxSetPr, mxSetPi, mxSetData,
mxSetImagData, mxSetIr, mxSetJc): Call mexMakeMemoryPersistent to
avoid a double free in ~mxArray destructor.

might affect your problem and so you probably need at least 2.9.17 to be
sure that this issue hasn't already been addressed.

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

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