Hello Palani,
I too had faced a similar
problem sometime back. Well I am not an expert. But going by the warnings, it
appears that you seem to be having problem with pointers. It is slightly
difficult to handle pointers in Matlab and also with persistence of variables.
The persistence of variables in C do not hold exactly true in Matlab. The Matlab
compiler allows you to create variables, but trying to access those memory
locations for clearing them will lead to this type of errors. Pay special
attention to the storage class especially if you are working with multiple
instantiations. Let your program not delete any pointers that you have created.
Let Matlab handle the clearing part. Hence try and avoid static, volatile
variables. You may like to go through the doccumentation specifically on the
subject I mentioned.
The compilers do not play a
major role as you are anticipating. Use the -g option for creating the debug
information. You may visit the Matlab site and look for help on
Debugging method for dll files. Try to debug and locate the exact
fault.
I hope these pointers help
you in overcomming the problem. All the best,
-Snehamoy
----- Original Message -----
From: Palani S
To: m...@yahoogroups.com
Sent: Sunday, May 02, 2004 12:33 PM
Subject: [matlab] Segmentation errors with MEX files
Greetings everyone,
I've only started using
MEX file feature in MATLAB and I have run into several problems which I
would like to clarify (some of them may be very specific to my C code, yet
I do not understand the reasons why they happened in the first place).
I have some C code that was written and tested in the Microsoft Visual Studio IDE. Somehow when the code was integrated into my MATLAB .m
file, I get a segmentation error (I checked for the arguments passed to the
function and they seem OK. To test if things were fine in the event this
code was not called from MATLAB, I executed the C code with correct
arguments and the program worked fine). I am not sure why this happens.
1. Does the choice of compilers (LCC or Visual Studio) I select using the mex -setup option make a difference to the way the program is supposed to behave - once the mex file is compiled in both cases and I
get the desired ..dll file? Interestingly my program seems to crash at
different instants when I select different compilers.
2. I seem to be
getting an error related to m_interpreter.dll and I followed the
instructions specified in http://www.mathworks.com/support/solutions/data/33527.html but that didnt
help either. Has anyone faced such an issue before?
For those
interested, a clip of what I see in the error log file (for the Visual
Studio compiler) has been attached at the end of this email.
3.
What is even more puzzling is that once my program crashed, I recompile and
rexecute and there are no segmentation faults this time.
I'd greatly appreciate anyone who can give me pointers in this regard. I'd be glad to send the source C files in case you're
interested.
Sorry for the rather long email and thanks for your
time!
Sincerely, Palani
<< error log file >> ----------------------------------
Configuration: MATLAB Version: 6.5.0.180913a
(R13) Operating System: Microsoft Windows XP Window
System: Version 5.1 (Build 2600) Processor
ID: x86 Family 15 Model 2 Stepping 7, GenuineIntel Virtual Machine: Java 1.3.1_01 with Sun Microsystems Inc. Java HotSpot(TM) Client VM (mixed mode)
Register
State: EAX = 00000000 EBX = 1f031068 ECX =
1d0d802c EDX = 00000030 ESI = 1d0d802c EDI = 00000001 EBP = 00dfd140 ESP = 00dfd130 EIP = 77c1c03a
FLG = 00010206
Stack Trace: [0] MSVCRT.DLL:0x77c1c03a(0,
0x1d0d802c, 10, 7) [1] Gateway.dll:0x10161e10(2, 7, 3, 0x10164098
"Creating State Table") [2] Gateway.dll:0x101611c1(0x166cafd0,
9, 8, 0x014785d8) [3] Gateway.dll:0x101610c0(2, 0x00dfd5d0, 7, 3) [4] libmex.dll:_mexRunMexFile(0, 0x00dfd5d0, 5, 0x00dfd6d4) + 71 bytes [5] m_interpreter.dll:void __cdecl
inCallMexFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag *
* const,void (__cdecl*)(int,struct mxArray_tag * * const,int,struct
mxArray_tag * * const),struct _mex_context *,struct mexfiles *)(0,
0x00dfd5d0, 5, 0x00dfd6d4) + 476 bytes [6]
m_interpreter.dll:void __cdecl inRunMexFile(int,struct mxArray_tag * *
const,int,struct mxArray_tag * * const,struct mexfiles *)(0, 0x00dfd5d0, 5,
0x00dfd6d4) + 126 bytes [7] m_interpreter.dll:void __cdecl
inExecMexFile(int,int,struct mxArray_tag * * const,struct
MATLAB_Function_tag *)(0, 5, 0x00dfd6d4, 0x1c033da8) + 82 bytes
[8] m_interpreter.dll:_inExecFunction(0, 5, 0x00dfd6d4, 0x1c033da8) + 38
bytes [9] m_interpreter.dll:_inMMexExecute(635, 0x1c033da8, 0, 5) +
533 bytes [10] m_interpreter.dll:enum opcodes __cdecl
inMMex(char const *,int,int,int,int *,int *)(0x01382f60 "Gateway", 635, 0,
5) + 94 bytes [11] m_interpreter.dll:int __cdecl
inInterp(enum inDebugCheck,int,int,struct inPcodeNest_tag volatile *)(2, 0,
0, 0x166f2ec8) + 2143 bytes [12]
m_interpreter.dll:_inInterPcode(2, 0x00dfdc54, 0, 0) + 193 bytes [13] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _m_parser_interface *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck)(0,
0x7a87fa78, 0x00dfdc54, 0x00dfdcf8) + 174 bytes [14]
m_interpreter.dll:_inEvalStringWithIsVarFcn(0x1633ecc0 "Gateway(d_array, h,
M, N, L)\n", 29, 0, 0) + 531 bytes [15]
m_interpreter.dll:_inEvalString(0x1633ecc0 "Gateway(d_array, h, M, N,
L)\n", 29, 0, 0) + 50 bytes [16] m_interpreter.dll:enum
inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int
*,enum inDebugCheck)(0x1633ecc0 "Gateway(d_array, h, M, N, L)\n", 0, 2, 0x00dfde30) + 68 bytes [17]
m_interpreter.dll:_inEvalCmdNoEnd(0x1633ecc0 "Gateway(d_array, h, M, N,
L)\n", 1, 0x0047f617, 11) + 16 bytes [18] matlab.exe:_mnParser(0,
271244, 0, 48) + 1001 bytes [19] matlab.exe:_WinMain@16(0x00400000
"MZ", 0, 271244, 1) + 3872 bytes [20]
matlab.exe:_WinMainCRTStartup(0, 1, 0x7ffdf000, 0x00450058) + 308 bytes [21] kernel32.dll:0x77e7eb69(0x0047172c, 0, 0, 1245343) ____________________________________________________________ Yahoo!
Messenger - Communicate instantly..."Ping" your friends today! Download
Messenger Now http://uk.messenger.yahoo.com/download/index.html
_____________________________________ Note: If you
do a simple "reply" with your email client, only the author of this message will
receive your answer. You need to do a "reply all" if you want your answer
to be distributed to the entire group.
_____________________________________ About this discussion group:
To Join: m...@yahoogroups.com
To Post:
m...@yahoogroups.com
To Leave: m...@yahoogroups.com
Archives: http://www.yahoogroups.com/group/matlab
More DSP-Related
Groups: http://www.dsprelated.com/groups.php3
|