|
From: Andrew M. <and...@db...> - 2007-09-25 14:24:25
|
"Navnidhi Sharma" <Nav...@us...> wrote on 25/09/2007
15:04:52:
> Use vector of chars in your wrapper.
My C wrapper does return a vector of chars. The return type is char*.
Maybe you had something else in mind. Did you think my code was in C++?
After all, C++ has a vector type. This code has to be in C so the C++
vector type is not available for me.
I saw in a post from years ago the following:
SWIG maps char * to a Java String, that is clearly documented. So it is
expecting the char * to be NULL terminated. Sounds like your data is not
NULL terminated, in which case you could apply the signed char[] typemaps.
%include "arrays_java.i"
%typemap(out) signed char[]
%{$result = SWIG_JavaArrayOutSchar(jenv, (signed char *)$1,
strlen($1)/*FillMeInAsSizeCannotBeDeterminedAutomatically*/); %}
%apply signed char[] {char *}
I don't understand this. It looks like it is using strlen so that would
not work for me. The data is binary and a zero byte could easily be
present. But I tried it anyway and it didn't work. The java output was
unchanged. The getters and setters for my char* data were still expressed
using the java String type.
> Thanks,
> Navnidhi
> -----Original Message-----
> From: swi...@li...
> To: swi...@li...
> Subject: [Swig-user] How to pass a char array back to java via SWIG and
> have it treated as a byte array ?
> I am using SWIG to wrap a closed-source third-party API. One of the
> routines in the API returns a block of bytes read from a binary file. In
> C
> the routine that does this returns a char* (and a length as well). I
> have
> written a little C wrapper around the API so that I can have a simple
> header that can be SWIG'd. My routine also returns a char*. The
> SWIG-generated code treats this as a string and uses the java String
> type.
> How do I make it use a byte array instead please?
Regards,
Andrew Marlow
----
There is an emerald here the size of a plover's egg!
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
|