I’m trying to update a project which uses SWIG to build an interface from ruby to matlab. The matlab C-API has changed and now I get the following error at runtime.
`mxCreateDoubleMatrix_730′: Expected argument 0 of type mwSize, but got Fixnum 20 (TypeError)
I found mwSize defined in tmwtypes.h, which was not being included in the SWIG interface file:
tmwtypes.h:typedef int mwSize;
tmwtypes.h:typedef size_t mwSize; /* unsigned pointer-width integer */
But, if I add tmwtypes.h to the include section of the SWIG interface, I still get the TypeError and if I add it to both the include and the parse section, I get the following compile error:
Error: CPP #error “”This code must be compiled using a 2’s complement representation for signed integer values””. Use the -cpperraswarn option to continue swig processing.
Giving up on tmwtypes.h, my solution is to add the following to the SWIG interface file.
%typemap(in) mwSize {
$1 = NUM2INT($input);
}
You can look at the complete SWIG interface file at:
https://github.com/morrifeldman/matlab-ruby/blob/master/ext/matlab_api/matlab_api.i
After adding this typemap, the program compiles and seems to work perfectly.
I have two related questions I would like answered:
-
Is the correct solution to the TypeError I am having with mwSize. Should I try something else instead?
-
I thought that including tmwtypes.h would fix my problem. Why didn’t it work?
For reference, I’m using OSX Mountain Lion with Xcode 4.5.2. The Makefile is calling gcc-4.2. ‘gcc-4.2 –version’ gives ‘i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1’
Thanks!
I was able to replace the
typemapwith:However, I can’t offer any insight into what is going on.