Date: Feb 1, 2013 8:01 AM
Author: Alle Mejie
Subject: MEX compilation: warning and segmentation fault

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