Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MEX compilation: warning and segmentation fault

Subject: MEX compilation: warning and segmentation fault

From: Alle Meije

Date: 1 Feb, 2013 13:01:08

Message: 1 of 3

Dear all.

I have a routine that computes the shift-invariant discrete wavelet transform, as specified in the Rice Wavelet Toolbox, in the frequency domain. The code is in MEX (c-syntax) and uses some extra routines to do imaginary polynomials etc in a separate file.

This code worked without problems in older matlab versions, and other matlab functions depend on it.

Now however, when I compile it now, there is first a warning message
>> mex fisidwt.c polyphase.c % message about different gcc version
>> mex fsidwt.c polyphase.c % message about different gcc version
  fsidwt.c: In function ‘multiMRFWD1D’:
  fsidwt.c:187: warning: cast to pointer from integer of different size
  fsidwt.c:188: warning: cast to pointer from integer of different size
  fsidwt.c:189: warning: cast to pointer from integer of different size
  fsidwt.c:190: warning: cast to pointer from integer of different size
which is weird because no integers are cast to pointers. But it's only a warning, so let's carry on.

Now the mex files fsidwt and fisidwt compute the forward and inverse frequency-domain shift-ivariant wavelet transform.

My test program is very simple:
>> clear all; len_sig=256; wlevels=3; numsig=1; numtest=1; % 256 points, 3 wavelet decomposition levels
>> st=4; ts=(1:(len_sig/st))'*(1:st); ts=ts(:); ts=ts*ones(1,numsig); Ts=fft(ts); % sawtooth with 4 points of increasing height and its FFT
>> h=[1;1]/sqrt(2); g=qmf(h); h=[h(:) g(:)]; H=fft(h,len_sig); % Haar wavelet filters and 256-point FFTs
>> [ffs ffd] = fsidwt(Ts, H, wlevels); % forward wavelet transform
>> ffr=fisidwt(ffs,ffd,cH,levels); % recontruction

The source files fsidwt.c, fisidwt.c and the helper routines polyphase.[chm] are zipped together in a file here: http://ubuntuone.com/6zXIIuA3J4OTTlSquycMlz

Unfortunately it exits with a segmentation violation whose cause I cannot trace from the output (see below)

How would I start finding the cause of this segmentation violation? Does it have to do with the warning? Is it the new Matlab version?

Thanks for your help,
Best wishes
Alle Meije Wink

------------------------------------------------------------------------
       Segmentation violation detected at Fri Feb 1 13:42:16 2013
------------------------------------------------------------------------

Configuration:
  Crash Decoding : Disabled
  Current Visual : 0x23 (class 4, depth 24)
  Default Encoding: UTF-8
  GNU C Library : 2.5 stable
  MATLAB License : 297662
  MATLAB Root : /usr/local/MATLAB/R2011a
  MATLAB Version : 7.12.0.635 (R2011a)
  Operating System: Linux 2.6.18-92.1.18.el5 #1 SMP Wed Nov 5 09:00:19 EST 2008 x86_64
  Processor ID : x86 Family 6 Model 15 Stepping 7, GenuineIntel
  Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System : The X.Org Foundation (11103000), display localhost:12.0

Fault Count: 1

Abnormal termination:
Segmentation violation

Register State (from fault):
  RAX = ffffffffac33a8a0 RBX = 0000000000000001
  RCX = 0000000000000000 RDX = 0000000000000800
  RSP = 0000000041030c40 RBP = 0000000041030d30
  RSI = 0000000000000002 RDI = 0000000000000000

   R8 = ffffffffac822e00 R9 = ffffffffac860070
  R10 = ffffffffac33a8a0 R11 = ffffffffac5d7140
  R12 = 0000000000000080 R13 = 00002aaaac28b600
  R14 = 00002aaaac81dad0 R15 = 00002aaaac320ce0

  RIP = 00002aaacecc9cf6 EFL = 0000000000010246

   CS = 0033 FS = 0000 GS = 0000

Stack Trace (from fault):
[ 0] 0x00002afeec631f49 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00474953 fl::sysdep::linux::unwind_stack(void const**, unsigned long, unsigned long, fl::diag::thread_context const&)+000009
[ 1] 0x00002afeec5e7dc1 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00171457 fl::diag::stacktrace_base::capture(fl::diag::thread_context const&, unsigned long)+000161
[ 2] 0x00002afeec5f10dd /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00209117
[ 3] 0x00002afeec5f1364 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00209764 fl::diag::terminate_log(char const*, fl::diag::thread_context const&, bool)+000100
[ 4] 0x00002afeed60dbe5 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00420837 fl::diag::terminate_log(char const*, ucontext const*, bool)+000085
[ 5] 0x00002afeed60ab54 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00408404
[ 6] 0x00002afeed60c03d /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00413757
[ 7] 0x00002afeed60c197 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00414103
[ 8] 0x00002afeed60cb1d /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00416541
[ 9] 0x00002afeed60d435 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00418869
[ 10] 0x000000392b40de70 /lib64/libpthread.so.0+00056944
[ 11] 0x00002aaacecc9cf6 /esa/data-amwink/matlab/rwt/fsidwt.mexa64+00003318
[ 12] 0x00002aaacecca1bf /esa/data-amwink/matlab/rwt/fsidwt.mexa64+00004543 mexFunction+000562
[ 13] 0x00002afef28bafaa /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmex.so+00049066 mexRunMexFile+000090
[ 14] 0x00002afef28b7f19 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmex.so+00036633
[ 15] 0x00002afef28b8bbe /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmex.so+00039870
[ 16] 0x00002afeed8927ef /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_dispatcher.so+00391151 Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)+000511
[ 17] 0x00002afeeddf0a13 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+03381779
[ 18] 0x00002afeeddf117b /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+03383675
[ 19] 0x00002afeeddf1cf4 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+03386612
[ 20] 0x00002afeedc743bf /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01823679
[ 21] 0x00002afeedc9faee /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+02001646
[ 22] 0x00002afeedc9fbe3 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+02001891
[ 23] 0x00002afeedd9d1e9 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+03039721
[ 24] 0x00002afeedbeb8e4 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01263844
[ 25] 0x00002afeedc447d9 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01628121
[ 26] 0x00002afeed8927ef /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_dispatcher.so+00391151 Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)+000511
[ 27] 0x00002afeedc209b2 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01481138
[ 28] 0x00002afeedbe2e13 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01228307
[ 29] 0x00002afeedbe1eb7 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01224375
[ 30] 0x00002afeedbe2397 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01225623
[ 31] 0x00002afeed3928fe /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwbridge.so+00108798
[ 32] 0x00002afeed3934ae /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwbridge.so+00111790 mnParser+000622
[ 33] 0x00002afeed5f5d39 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00322873 mcrInstance::mnParser_on_interpreter_thread()+000041
[ 34] 0x00002afeed5d8db2 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00204210
[ 35] 0x00002afeed5d8ec0 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00204480
[ 36] 0x00002afef5a42db6 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwuix.so+00437686
[ 37] 0x00002afef5a4c13d /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwuix.so+00475453
[ 38] 0x00002afef50c20bd /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libuij.so+00217277 sysq::during_F<boost::weak_ptr<sysq::ws_ppeHook>, boost::shared_ptr<sysq::ws_ppeHook> > std::for_each<__gnu_cxx::__normal_iterator<boost::weak_ptr<sysq::ws_ppeHook>*, std::vector<boost::weak_ptr<sysq::ws_ppeHook>, std::allocator<boost::weak_ptr<sysq::ws_ppeHook> > > >, sysq::during_F<boost::weak_ptr<sysq::ws_ppeHook>, boost::shared_ptr<sysq::ws_ppeHook> > >(__gnu_cxx::__normal_iterator<boost::weak_ptr<sysq::ws_ppeHook>*, std::vector<boost::weak_ptr<sysq::ws_ppeHook>, std::allocator<boost::weak_ptr<sysq::ws_ppeHook> > > >, __gnu_cxx::__normal_iterator<boost::weak_ptr<sysq::ws_ppeHook>*, std::vector<boost::weak_ptr<sysq::ws_ppeHook>, std::allocator<boost::weak_ptr<sysq::ws_ppeHook> > > >, sysq::during_F<boost::weak_ptr<sysq::ws_ppeHook>, boost::shared_ptr<sysq::ws_ppeHook>
>)+000077
[ 39] 0x00002afef50c3989 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libuij.so+00223625
[ 40] 0x00002afef50c04ae /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libuij.so+00210094 svWS_ProcessPendingEvents(int, int, bool)+000494
[ 41] 0x00002afeed5d71c7 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00197063
[ 42] 0x00002afeed5d760a /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00198154
[ 43] 0x00002afeed5d7d6f /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00200047
[ 44] 0x000000392b4062f7 /lib64/libpthread.so.0+00025335
[ 45] 0x000000392a8d1e3d /lib64/libc.so.6+00859709 clone+000109

Subject: MEX compilation: warning and segmentation fault

From: James Tursa

Date: 1 Feb, 2013 16:17:08

Message: 2 of 3

"Alle Meije " <a.m.wink@gmail.com> wrote in message <kegeak$20c$1@newscl01ah.mathworks.com>...
>
> This code worked without problems in older matlab versions, and other matlab functions depend on it.
>
> Now however, when I compile it now, there is first a warning message
> >> mex fisidwt.c polyphase.c % message about different gcc version
> >> mex fsidwt.c polyphase.c % message about different gcc version
> fsidwt.c: In function ‘multiMRFWD1D’:
> fsidwt.c:187: warning: cast to pointer from integer of different size
> fsidwt.c:188: warning: cast to pointer from integer of different size
> fsidwt.c:189: warning: cast to pointer from integer of different size
> fsidwt.c:190: warning: cast to pointer from integer of different size
> which is weird because no integers are cast to pointers. But it's only a warning, so let's carry on.

Maybe you don't think any integers are being cast to pointers, but the compiler certainly does. What do those lines look like?

James Tursa

Subject: MEX compilation: warning and segmentation fault

From: Alle Meije

Date: 4 Feb, 2013 15:14:08

Message: 3 of 3

"James Tursa" wrote in message <kegpq4$ish$1@newscl01ah.mathworks.com>...
> "Alle Meije " <a.m.wink@gmail.com> wrote in message <kegeak$20c$1@newscl01ah.mathworks.com>...
> >
> > This code worked without problems in older matlab versions, and other matlab functions depend on it.
> >
> > Now however, when I compile it now, there is first a warning message
> > >> mex fisidwt.c polyphase.c % message about different gcc version
> > >> mex fsidwt.c polyphase.c % message about different gcc version
> > fsidwt.c: In function ‘multiMRFWD1D’:
> > fsidwt.c:187: warning: cast to pointer from integer of different size
> > fsidwt.c:188: warning: cast to pointer from integer of different size
> > fsidwt.c:189: warning: cast to pointer from integer of different size
> > fsidwt.c:190: warning: cast to pointer from integer of different size
> > which is weird because no integers are cast to pointers. But it's only a warning, so let's carry on.
>
> Maybe you don't think any integers are being cast to pointers, but the compiler certainly does. What do those lines look like?
>
> James Tursa

Ah, the lines are in the code in the zipfile at http://ubuntuone.com/6zXIIuA3J4OTTlSquycMlz -- and then line numbers 187-190 of fsidwt.c.

Those lines read:
Hfilter2d=(dComplexMat)dComplexMake2D(hcomp[0],NQ,Q);
Gfilter2d=(dComplexMat)dComplexMake2D(hcomp[1],NQ,Q);
Detail2d=(dComplexMat)dComplexMake2D(workspaced,Q,NQ);
Approx2d=(dComplexMat)dComplexMake2D(workspacec,Q,NQ);

All the LHS are of type
   dComplexMat
which is
   typedef struct {double r,i;} dComplex;
   typedef dComplex *dComplexVec;
   typedef dComplexVec *dComplexMat;
All the RHS are of type
  (dComplexVec, long, long)
and the code of dComplexMake2D() is:

dComplexMat dComplexMake2D(
dComplexVec array1D,
int width, int height) {
register int i;
dComplexMat theMatrix=
(dComplexMat)mxCalloc(width,sizeof(dComplexVec));
theMatrix[0]=(dComplexVec)array1D;
for(i=1;i<width;i++)
theMatrix[i] = theMatrix[i-1] + height;
return theMatrix;
}

turning a vector of complex numbers into a matrix. The only 'int's in that routine are for the matrix width and height, but they are not converted to pointers???

If the compiler 'thinks' they should be, I would very much like to know how that works...

With best wishes,
Alle Meije

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us