From: fmotif <fm...@ya...> - 2006-11-06 22:30:36
|
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". > > > > William > > > > > ------------------------------ > > Message: 7 > Date: Fri, 03 Nov 2006 22:11:14 +0000 > From: William S Fulton <ws...@fu...> > Subject: Re: [Swig-user] Generated code for > std::string director seems > wrong for java... > To: Mark Donszelmann > <Mar...@sl...> > Cc: swi...@li... > Message-ID: <454...@fu...> > Content-Type: text/plain; charset=ISO-8859-1 > > Mark Donszelmann wrote: > > Hi > > > > the typemap in Lib/java/std_string.i > > > > > %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) > const > > string & > > %{ if(!$input) { > > SWIG_JavaThrowException(jenv, > SWIG_JavaNullPointerException, "null > > std::string$ > > return $null; > > } > > const char *$1_pstr = (const char > *)jenv->GetStringUTFChars($input, 0); > > if (!$1_pstr) return $null; > > /* possible thread/reentrant code problem */ > > static std::string $1_str($1_pstr); > > $result = &$1_str; > > jenv->ReleaseStringUTFChars($input, $1_pstr); > %} > > > > > > generates code like: > > > > static std::string > c_result_str(c_result_pstr); > > > > which works the first time this method is called. > The second time the > > initialization of > > c_result_str seems to not be done (g++ 4.0.1 MacOS > X 10.4.8) so the > > result of > > the first call is returned. > > > > I fixed this by doing: > > > > static std::string c_result_str; > > c_result_str = c_result_pstr; > > > > which does return the correct value. > > > > Is this a bug in SWIG (or in g++ 4.0.1 ?) or in my > thinking of c++? > > > > Definitely a SWIG bug. Your fix is the right one and > is now committed to > cvs. > > William > > > > ------------------------------ > > Message: 8 > Date: Fri, 3 Nov 2006 14:10:45 -0800 > From: "Sohail Somani" <s.s...@fi...> > Subject: Re: [Swig-user] Generated code for > std::string director seems > wrong for java... > To: "William S Fulton" <ws...@fu...>, > "Mark Donszelmann" > <Mar...@sl...> > Cc: swi...@li... > Message-ID: > > <1C1...@xb...> > Content-Type: text/plain; charset="us-ascii" > > > -----Original Message----- > > From: swi...@li... > > [mailto:swi...@li...] > On Behalf Of > > William S Fulton > > > I fixed this by doing: > > > > > > static std::string c_result_str; > > > c_result_str = c_result_pstr; > > > > > > which does return the correct value. > > > > > > Is this a bug in SWIG (or in g++ 4.0.1 ?) or in > my thinking of c++? > > > > > > > Definitely a SWIG bug. Your fix is the right one > and is now > > committed to > > cvs. > > Why does it need a static? To prevent copies? Well, > it does a copy there > anyway... Might as well return c_result_pstr. > > > > ------------------------------ > > Message: 9 > Date: Fri, 03 Nov 2006 17:17:50 -0500 > From: Dave Ludwig <dl...@si...> > Subject: [Swig-user] Hopefully an easy one - > SWIGTYPE_p_string > To: Swig User List <swi...@li...> > Message-ID: <454...@si...> > Content-Type: text/plain; charset=ISO-8859-1; > format=flowed > > Using stl::string type in my C++ project. > I have std_string.i included in my input file and > also a "using > namespace std" command. > > One of my C++ member functions is defined in C++ as: > void SetMpeConfigFile (const string& val) > > In Java when I try to use > mpe.SetMpeConfigFile("Hello.cfg"); > > I get an error message > The method SetMpeConfigFile(SWIGTYPE_p_string) in > the type MpeApp is not > applicable for the > arguments (String) > > Thanks. > > -- > Dave Ludwig > SISCO, Inc. > > > > > ------------------------------ > > Message: 10 > Date: Fri, 3 Nov 2006 22:33:40 +0000 (UTC) > From: stef_ <st....@vi...> > Subject: Re: [Swig-user] R: Re: Wrapping > To: swi...@li... > Message-ID: <loo...@po...> > Content-Type: text/plain; charset=us-ascii > > st.marengo <at> virgilio.it <st.marengo <at> > virgilio.it> writes: > > After a lot of attempts, I have compiled something > working for "int *". > There is only the problem of a memory leak. :( > > The next step for me is doing to same with a > "virtual int *getValue();" > converted to java byte[]. > > Bye > > class > Alpha { > public: > virtual int *getValue(); > }; > > %include "typemaps.i" > %include "arrays_java.i" > > // this affects moduleJNI.java in doing upcall() > %typemap(javadirectorout) int * "$javacall" > > // this affects directorxxx.java virtual method body > %typemap(javaout) int * { return $jnicall; } > > // this affects module_wrap.cxx for jresult of > CallStaticObjectMethod() > %typemap(jni) int * "jintArray" > > // this affects moduleJNI.java in return type of > method doing upcall() > %typemap(jtype) int * "int[]" > > // this affects directorxxx.java return type of > virtual method > %typemap(jstype) int * "int[]" > > // this affects module_wrap.cxx in managing result > of CallStaticObjectMethod() > %typemap(directorout) int * { result = > jenv->GetIntArrayElements(jresult, 0); } > > // this affects module_wrap.cxx for signature in > swig_connect_director() > %typemap(directorin, descriptor="[I") int * "" > > > > > ------------------------------ > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support > web services, security? > Get stuff done quickly with pre-integrated > technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 > based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > ------------------------------ > > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > > > End of Swig-user Digest, Vol 6, Issue 5 > *************************************** > __________________________________________________ Fale com seus amigos de graça com o novo Yahoo! Messenger http://br.messenger.yahoo.com/ |