From: Mathieu M. <mat...@gm...> - 2008-11-13 19:34:45
|
On Thu, Nov 13, 2008 at 8:19 PM, Mathieu Malaterre <mat...@gm...> wrote: > Antti, > > On Wed, Nov 12, 2008 at 8:19 AM, Antti Karanta <ant...@na...> wrote: >> >> On Mon, 10 Nov 2008 12:53:10 +0200, Mathieu Malaterre >> <mat...@xx...> wrote: >> >>> Alright. I tried using my installed swig: SWIG Version 1.3.36. I >>> grabbed the .i file you mentioned. During compilation I am getting: >>> >>> /home/mathieu/Projects/gdcm/trunk/Examples/Csharp/DecompressImage.cs(64,8): >>> error CS1502: The best overloaded method match for >>> `gdcm.Pixmap.GetBuffer(string)' has some invalid arguments >>> /home/mathieu/Projects/gdcm/debug-gcc/bin/gdcm_csharp.dll (Location of >>> the symbol related to previous error) >>> /home/mathieu/Projects/gdcm/trunk/Examples/Csharp/DecompressImage.cs(64,8): >>> error CS1503: Argument 1: Cannot convert type `byte[]' to `string' >> >> What about output from swig? Did it complain about anything? >> >> >>> If I check the generated .cs file, I can still find: >>> >>> public bool GetBuffer(string buffer) { >>> bool ret = gdcmPINVOKE.Pixmap_GetBuffer(swigCPtr, buffer); >>> return ret; >>> } >>> >>> >>> Here is how I used your suggestion: >>> >>> %include "gdcm_arrays_csharp.i" // local copy of arrays_csharp.i from svn >>> %apply byte OUTPUT[] { char* buffer } ; >>> %include "gdcmPixmap.h" >>> >>> and gdcmPixmap.h contains: >>> >>> class GDCM_EXPORT Pixmap : public Object >>> { >>> public: >>> ... >>> bool GetBuffer(char *buffer) const; >>> }; >> >> Looks perfectly ok to me. I have to admit, though, that I have only been >> using swig to wrap c, not c++, but I would not think that makes a >> difference about using basic typemaps. > > > Ok I have spent way too much time on this issue. So here is my minimal example: > > I copy all files from: > http://swig.svn.sourceforge.net/viewvc/swig/trunk/Examples/csharp/arrays/ > > Changed example.h into: > > -------------------------------------------------------- > void myArrayCopy( char*sourceArray, char* targetArray, int nitems ); > void myArraySwap( char* array1, char* array2, int nitems ); > -------------------------------------------------------- > > (modified example.c accordingly) > > then modified example.i > > -------------------------------------------------------- > /* File : example.i */ > %module example > > %include "arrays_csharp.i" > > %apply byte INPUT[] { char* sourceArray } > %apply byte OUTPUT[] { char* targetArray } > > %include "example.h" > > %clear int* sourceArray; > %clear int* targetArray; > -------------------------------------------------------- > > > and finally runme.cs is : > > > using System; > > public class runme > { > static void Main() > { > byte[] source = { 1, 2, 3 }; > byte[] target = new byte[ source.Length ]; > > example.myArrayCopy( source, target, target.Length ); > > Console.WriteLine( "Contents of copy target array using default > marshaling" ); > PrintArray( target ); > > } > > static void PrintArray( byte[] a ) > { > foreach ( byte i in a ) > Console.Write( "{0} ", i ); > Console.WriteLine(); > } > } > > > During compilation I am getting: > > make[1]: Entering directory `/home/mathieu/Software/swig/Examples/csharp/arrays' > gmcs -nologo -unsafe -out:runme.exe *.cs > runme.cs(10,13): error CS1502: The best overloaded method match for > `example.myArrayCopy(string, string, int)' has some invalid arguments > example.cs(14,22): (Location of the symbol related to previous error) > runme.cs(10,13): error CS1503: Argument 1: Cannot convert type > `byte[]' to `string' > Compilation failed: 2 error(s), 0 warnings > make[1]: *** [csharp_compile] Error 1 > make[1]: Leaving directory `/home/mathieu/Software/swig/Examples/csharp/arrays' > make: *** [csharp] Error 2 > > > > I am now convinced that 'char' is a *very* special case, it would be > nice if someone could comment on that, and in particular on how to > change that behavior. > > changing to 'unsigned char' leads to a little improvement: > > > gmcs -nologo -unsafe -out:runme.exe *.cs > runme.cs(10,13): error CS1502: The best overloaded method match for > `example.myArrayCopy(SWIGTYPE_p_unsigned_char, > SWIGTYPE_p_unsigned_char, int)' has some invalid arguments > example.cs(14,22): (Location of the symbol related to previous error) > runme.cs(10,13): error CS1503: Argument 1: Cannot convert type > `byte[]' to `SWIGTYPE_p_unsigned_char' > Compilation failed: 2 error(s), 0 warnings > make[1]: *** [csharp_compile] Error 1 > make[1]: Leaving directory `/home/mathieu/Software/swig/Examples/csharp/arrays' > make: *** [csharp] Error 2 this thing is driving me nuts ! I can get it to work with 'short', but not 'unsigned short'... gmcs -nologo -unsafe -out:runme.exe *.cs runme.cs(10,13): error CS1502: The best overloaded method match for `example.myArrayCopy(SWIGTYPE_p_unsigned_short, SWIGTYPE_p_unsigned_short, int)' has some invalid arguments example.cs(14,22): (Location of the symbol related to previous error) runme.cs(10,13): error CS1503: Argument 1: Cannot convert type `ushort[]' to `SWIGTYPE_p_unsigned_short' Compilation failed: 2 error(s), 0 warnings make[1]: *** [csharp_compile] Error 1 make[1]: Leaving directory `/home/mathieu/Software/swig/Examples/csharp/arrays' make: *** [csharp] Error 2 -- Mathieu |