|
RE: Java char *INOUT doesn't OUT: msg#00156programming.swig
signed char* is treated as a pointer to an array by default so does not handle null terminated strings. The signed char*INOUT typemaps are for single characters. If you want an in/out string, you'll have to use StringBuffer and debug/modify the SBUF typemaps in the Examples/java/typemaps example to suite. William >-----Original Message----- >From: swig-admin@xxxxxxxxxxxxxxx [mailto:swig-admin@xxxxxxxxxxxxxxx]On >Behalf Of Gary Nissen >Sent: 23 September 2004 20:22 >To: William S Fulton >Cc: swig@xxxxxxxxxxxxxxx >Subject: Re: [Swig] Java char *INOUT doesn't OUT > > >William, > >Thanks for the input. For clarification, the char* are >basically strings (not single chars) that are passed back and >forth with this DLL. > >Does the signed char * properly handle null terminating the Strings? > >Thanks, > >Gary > > >At 04:06 PM 9/22/2004, William S Fulton wrote: >>Gary Nissen wrote: >> >>>Hi, >>>I'm using SWIG-1.3.22 on Windows with Java JDK 1.4.2. >>>I'm trying to wrap a C DLL. All parameters are passed as >pointers (int *, double *, and char *). Most parameters are >*INPUT, but some are *INOUT. The int *INOUT and double *INOUT >work as expected by turning the parameter into a single >dimensional array. But a char *INOUT turns the parameter into >a String, basically making it a char *INPUT. >>>I expected the char *INOUT to allow me to pass Strings back >and forth via a 1-dimensional array just like int *INOUT. Am >I off track? Is there a better method to do this? >>>Through my struggles I also tried the *SBUF and *BYTE >methods. Unfortunately neither worked for me. >>>The *SBUF caused Access Violations because the char array >was a different length than the string contained in the >StringBuffer. It was using the capacity of a StringBuffer >instead of the length of the String contained in it. I tried >changing the typemap to use length. Then I received Access >Violations when the resulting string was being appended back >to the StringBuffer. I wasn't able to figure out why that was failing. >>>The *BYTE caused garbage to be pasted back into my String. >I was using the BYTE method this way: >>>String s = "0123456789"; >>>byte[] b = s.toByteArray(); >>>int r = DLLWrapper.getResult(b); >>>s = new String(b); >>>System.out.println(s); >>>This resulted in garbage printouts. >>>Any advice on the best/easiest way to do this? >> >>SWIG wraps char* as a string, that is well documented. To >change the behaviour of char* to a pointer to an in/out single >char character, apply the 'signed char *' typemaps. >> >>%include "typemaps.i" >>%apply signed char *INOUT {char *pnum}; >>%typemap(freearg) char *pnum ""; >> >>void foo(char *pnum); >> >>Unfortunately the default char* typemaps require a freearg >typemap and this is still picked up, thus the extra typemap >above to clear the freearg typemap. I'll change this so it >won't be necessary in the future. >> >>William >>_______________________________________________ >>Swig maillist - Swig@xxxxxxxxxxxxxxx >>http://mailman.cs.uchicago.edu/mailman/listinfo/swig > > > >_______________________________________________ >Swig maillist - Swig@xxxxxxxxxxxxxxx >http://mailman.cs.uchicago.edu/mailman/listinfo/swig > Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | swig on vxworks: 00156, Ranjan, Ashish (GE Healthcare) |
|---|---|
| Next by Date: | Re: Problems with %rename (const): 00156, Emanuel Greisen |
| Previous by Thread: | Re: Java char *INOUT doesn't OUTi: 00156, Gary Nissen |
| Next by Thread: | Supplying default OUTPUT values: 00156, Cory Omand |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |