From: fmotif <fm...@ya...> - 2006-11-09 23:52:23
|
Hi William I compiled the examples... I saw the verbose from the makefile getting out the -s option ... My apologies, but I can´t undarstand how gifplot.h was wrapped, I don´t see in the interface file Examples/interface/gifplot.i how "double **" was been wrapped. I did: make check-java-gifplot The output: ----------------------------- make -f ../../../Makefile SRCS='' SWIG='/u/swig/swig-1.3.29/swig' \ INCLUDES='-I../../Include' LIBS='-L../.. -lgifplot' SWIGOPT='-I../../Include -noproxy' \ TARGET='gifplot' INTERFACE='gifplot.i' java /u/swig/swig-1.3.29/swig -java -I../../Include -noproxy gifplot.i cc -c gifplot_wrap.c -I../../Include -I/usr/jdk/instances/jdk1.5.0/include -I/usr/jdk/instances/jdk1.5.0/include/solaris ld -G gifplot_wrap.o -L../.. -lgifplot -o libgifplot.so javac *.java -------------------------- it looks like magic !!! Fabio --- William S Fulton <ws...@fu...> escreveu: > Run: > > make check-java-gifplot in the top level directory. > > Only works on unix. > > William > > fmotif wrote: > > Hi William > > > > I saw in the gifplot.h example a struct that uses > > double **, but I didn´t understand how it was > wrapped > > in the gifplot.i. It seems me it was bypassed. (At > the > > moment I have problems with examples building - > may be > > because I´m not administrator - just I can´t "make > > install") > > > > --------- > > Gifplot.h > > --------- > > typedef unsigned char Pixel; > > typedef float Zvalue; > > > > typedef struct FrameBuffer { > > Pixel **pixels; > > Zvalue **zbuffer; > > unsigned int height; > > unsigned int width; > > int xmin; > > int ymin; > > int xmax; > > int ymax; > > ... > > } > > --------- > > Gifplot.i > > --------- > > typedef unsigned char Pixel; > > typedef float Zvalue; > > > > typedef struct FrameBuffer { > > unsigned int height; > > unsigned int width; > > int xmin; > > int ymin; > > int xmax; > > int ymax; > > ... > > } > > > > This Zvalue seems have the same purpose of the > mine Z. > > > > At the moment I already work with a struct that > > defines a single pointer; > > > > This is my test code: > > ------ > > > > SWIGTYPE_p_StructGravacaoXyz xyz = > > Baseproj.new_StructGravacaoXyz(); > > > > SWIGTYPE_p_double p_x = > Baseproj.new_doubleArray(2); > > > > Baseproj.doubleArray_setitem(p_x,0, 1.1); > > Baseproj.doubleArray_setitem(p_x,1, 1.2); > > > > double a[] = {0,0}; > > > > a[0] = Baseproj.doubleArray_getitem(p_x,0); > > a[1] = Baseproj.doubleArray_getitem(p_x,1); > > ---- > > > > Thanks > > Fabio > > Rio de Janeiro > > > > --- William S Fulton <ws...@fu...> > > escreveu: > > > >> For your short *reclass, you can use > arrays_java.i > >> as follows: > >> > >> %include <arrays_java.i> > >> > >> /* > >> The default typemap which needs to be overridden > as > >> the interface does > >> not indicate how big the C array is. > >> %typemap(out) short[] > >> %{$result = SWIG_JavaArrayOutShort(jenv, $1, > >> FillMeInAsSizeCannotBeDeterminedAutomatically); > %} > >> */ > >> > >> // replace 16 with whatever the array size is > >> %typemap(out) short[] > >> %{$result = SWIG_JavaArrayOutShort(jenv, $1, 16); > %} > >> > >> // apply short[] typemaps from arrays_java.i > >> %apply short[] { short *reclas } > >> > >> > >> %inline %{ > >> typedef struct > >> { > >> short *reclas; > >> } XYZ; > >> %} > >> > >> Basically you are using the typemaps in > >> arrays_java.i and tweaking a bit > >> to fill in the missing information. > >> > >> As for your double** type, I don't recall ever > >> seeing any 2D array > >> typemaps. You would need to take some of the > >> typemaps in arrays_java.i > >> and tweak for 2D arrays. > >> > >> Hope that helps. > >> > >> William > >> > >> fmotif wrote: > >>> William > >>> > >>> Thanks for the answer... > >>> > >>> The pointers defined into the struct XYZ > >> represent > >>> arrays, the double pointer (double **) is a > matrix > >> 2D > >>> and (char **) represents an array of strings. > >>> > >>> To wrap the array of strings i´m using the > >> STRING > >>> pattern, but about the others, any one have an > >> example > >>> with a case looks like this, but using only C > >> (without > >>> C++). > >>> > >>> I looked at arrays_java.i, but I need an easy > >>> example ... > >>> > >>> Fabio > >>> > >>> > >>>> fmotif wrote: > >>>>> Hi > >>>>> > >>>>> at the moment i?m not expert with swig > scripting > >>>>> language... > >>>>> > >>>>> I?m trying to generate wrappers for JAVA to > this > >>>>> srtuct > >>>>> > >>>>> typedef struct > >>>>> { > >>>>> short *reclas; > >>>>> char **siglas; > >>>>> double *X; > >>>>> double *Y; > >>>>> double **Z; > >>>>> char **descrZs; > >>>>> long numZs; > >>>>> long numSiglas; > >>>>> } XYZ; > >>>>> > >>>>> the problems are the double *, double ** and > >> short > >>>> *, > >>>>> that generates: SWIG_p..., I tryied resolve > the > >>>> short > >>>>> * with: > >>>>> > >>>>> %include typemaps.i > >>>>> %apply short *INPUT {short *}; > >>>>> typedef struct { ... > >>>>> } > >>>>> > >>>>> but the java code doesn?t compile > >>>>> > >>>>> thanks > >>>>> > >>>> You need to first say how you want to marshal > >> these > >>>> types for Java, eg > >>>> is reclas a pointer to a single element or an > >> array? > >>>> The same for all > >>>> the pointers in your XYZ class above. The > >> approach > >>>> to wrap this would be > >>>> different for each. Look at arrays_java.i for > >>>> arrays. > >>>> > >>>> William > >>>> > >>>> > >>>> > >>>> ------------------------------ > >>>> > >>>> Message: 6 > >>>> Date: Fri, 3 Nov 2006 15:57:50 -0600 > >>>> From: robert engels <re...@ix...> > >>>> Subject: Re: [Swig-user] unsigned char pointer > as > >>>> byte[] in Java ? > >>>> To: William S Fulton <ws...@fu...> > >>>> Cc: swi...@li... > >>>> Message-ID: > >>>> > >> > <E63...@ix...> > >>>> Content-Type: text/plain; charset=US-ASCII; > >>>> delsp=yes; format=flowed > >>>> > >>>> Thank you very much. I will test it out. > >>>> > >>>> I confess I don't know SWIG at all (the mapping > >>>> documents related to > >>>> java were not very clear - at least to me). I > am > >>>> attempting to help > >>>> out with some other projects and they used it > for > >>>> JNI integration. I > >>>> have started to work on a custom JNI > >> implementation > >>>> because I could > >>>> not get this to work. > >>>> > >>>> Robert > >>>> > >>>> On Nov 3, 2006, at 3:54 PM, William S Fulton > >> wrote: > >>>>> robert engels wrote: > >>>>>> Hello all, > >>>>>> > >>>>>> I have a C struct that I am trying to use > from > >>>> Java, accessing the > >>>>>> unsigned char * as a byte[]. (It seems that > >>>> arrays_java.i wants to > >>>>>> access this as a short[] for some reason). > >>>>>> > >>>>> It is the most appropriate type that covers > all > >>>> possible values of an > >>>>> unsigned char array. > >>>>> > >>>>>> struct mystruct { > >>>>>> unsigned char *mydata; > >>>>>> int mydatalen; > >>>>>> }; > >>>>>> > >>>>>> I looked at various.i and saw the 'accessing > a > >>>> char* as a byte[], but > >>>>>> when I create the following for an unsigned > >> char > >>>> * > >>>>>> %typemap(jni) (unsigned char *BYTE) > >> "jbyteArray" > >>>>>> %typemap(jtype) (unsigned char *BYTE) > "byte[]" > >>>>>> %typemap(jstype) (unsigned char *BYTE) > "byte[]" > >>>>>> %typemap(in) unsigned char *BYTE { $1 = > >> (unsigned > >>>> char *) > >>>>>> JCALL2(GetByteArrayElements, jenv, $input, > 0); > >>>>>> } > >>>>>> %typemap(argout) unsigned char *BYTE { > >>>>>> JCALL3(ReleaseByteArrayElements, jenv, > >>>> $input, (jbyte *) $1, 0); > >>>>>> } > >>>>>> %typemap(javain) (unsigned char *BYTE) > >>>> "$javainput" > >>>>>> /* Prevent default freearg typemap from being > >>>> used */ > >>>>>> %typemap(freearg) (unsigned char *BYTE) "" > >>>>>> > >>>>>> and then try to apply it using: > >>>>>> > >>>>>> %apply unsigned char *BYTE { (unsigned char > >>>> *mydata) }; > >>>>>> it generates the following code > >>>>>> > >>>>>> public void setMydata(byte[] value) { > >>>>>> > MySwigTestJNI.mystruct_mydata_set(swigCPtr, > >>>> value); > >>>>>> } > >>>>>> > >>>>>> public byte[] getMydata() { > >>>>>> long cPtr = > >>>> MySwigTestJNI.mystruct_mydata_get(swigCPtr); > >>>>>> return (cPtr == 0) ? null : new > >>>> SWIGTYPE_p_unsigned_char(cPtr, > >>>>>> false); > >>>>>> } > >>>>>> > >>>>>> which does not compile > >>>>>> > >>>>>> mystruct.java:41: incompatible types > >>>>>> found : byte[] > >>>>>> required: long > >>>>>> long cPtr = > >>>> MySwigTestJNI.mystruct_mydata_get(swigCPtr); > >>>>>> > > >>>> ^ > >>>>>> mystruct.java:42: incompatible types > >>>>>> found : > >> net.sf.libusb.SWIGTYPE_p_unsigned_char > >>>>>> required: byte[] > >>>>>> return (cPtr == 0) ? null : new > >>>> SWIGTYPE_p_unsigned_char(cPtr, > >>>>>> false); > >>>>>> ^ > >>>>>> I have attached a complete testcase with > >>>> makefile. I am sure it is > >>>>>> something simple, but I can't seem to find > it. > >>>>>> > >>>>> You are missing the javaout typemap. You > >> probably > >>>> need: > >>>>> %typemap(javaout) (unsigned char *BYTE) { > >>>>> return $jnicall; > >>>>> } > >>>>> > >>>>> Also your freearg typemap has a typo for the > >> type, > >>>> it should be > >>>>> "unsigned char" not "unsignedchar". > >>>>> > > > > > > > > __________________________________________________ > > Fale com seus amigos de graça com o novo Yahoo! > Messenger > > http://br.messenger.yahoo.com/ > > > > __________________________________________________ Fale com seus amigos de graça com o novo Yahoo! Messenger http://br.messenger.yahoo.com/ |