Forum: GNU Radio swig question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dad63495ad946099d72d3a24387d0ed6?d=identicon&s=25 Brett L. Trotter (Guest)
on 2007-05-25 01:44
(Received via mailing list)
I've made a swig wrapper for some code that needs a char pointer passed
in, how do I do such a thing?
Dad63495ad946099d72d3a24387d0ed6?d=identicon&s=25 Brett L. Trotter (Guest)
on 2007-05-25 02:07
(Received via mailing list)
Brett L. Trotter wrote:
> I've made a swig wrapper for some code that needs a char pointer passed
> in, how do I do such a thing?
>
>
>
Thinking about this more, maybe I need to give more information.

I've wrapped Phil Karn's FEC library and I'm trying to call
encode_rs_char:
 void encode_rs_char(void *rs,unsigned char *data, unsigned char
*parity);
I passed it a string of a correct length, like I did for data, and it
only complained about the one for parity

my python looks like this

from fec import *

def main():
        # make a test string with a predictable value
        teststr = ''
        for i in range(127):
                teststr = teststr + chr(i)
        # make a 127 byte long string to fill with parity
        paritystr = chr(0) * 127
        # create a handle for the reed-solomon function with the right
params
        rs_handle = init_rs_char(8, 0x187, 1, 1, 128, 0)
        # do the actual encoding
        encode_rs_char(rs_handle, teststr, paritystr)


main()


and I get:
Traceback (most recent call last):
  File "./test.py", line 18, in ?
    main()
  File "./test.py", line 15, in main
    encode_rs_char(rs_handle, teststr, paritystr)
TypeError: in method 'encode_rs_char', argument 2 of type 'unsigned char
*'


so what can I pass it?
821c1adf3f4be2f2aa6fbc89cce4c69a?d=identicon&s=25 Michael Dickens (Guest)
on 2007-05-25 03:07
(Received via mailing list)
On May 24, 2007, at 8:07 PM, Brett L. Trotter wrote:
> Traceback (most recent call last):
>   File "./test.py", line 18, in ?
>     main()
>   File "./test.py", line 15, in main
>     encode_rs_char(rs_handle, teststr, paritystr)
> TypeError: in method 'encode_rs_char', argument 2 of type 'unsigned
> char *'
>
> so what can I pass it?

I think you'll need to pass "const std::vector<char> &" since C++,
SWIG, and Python all know what this is [a reference to a std::vector
of chars, that cannot be modified by the receiving function].  That
works for other blocks used in GNU Radio, IIRC. - MLD
745d8202ef5a58c1058d0e5395a78f9c?d=identicon&s=25 Eric Blossom (Guest)
on 2007-05-25 06:06
(Received via mailing list)
On Thu, May 24, 2007 at 06:43:21PM -0500, Brett L. Trotter wrote:
> I've made a swig wrapper for some code that needs a char pointer passed
> in, how do I do such a thing?

Use const std::string &foo instead of char *.

For a longer answer, see the swig docs.

Eric
745d8202ef5a58c1058d0e5395a78f9c?d=identicon&s=25 Eric Blossom (Guest)
on 2007-05-25 06:07
(Received via mailing list)
On Thu, May 24, 2007 at 07:07:09PM -0500, Brett L. Trotter wrote:
> Brett L. Trotter wrote:
> > I've made a swig wrapper for some code that needs a char pointer passed
> > in, how do I do such a thing?
> >
> >
> >
> Thinking about this more, maybe I need to give more information.

Read up on typemaps in the swig documentation.

Eric
53e914bcf9093cbd67202d1bed80d8cf?d=identicon&s=25 Steven Clark (Guest)
on 2007-05-25 17:32
(Received via mailing list)
Brett-

I am also very interested in wrapping a C-based FEC library. Could you
please keep us updated with your progress?
Thanks.

-Steven
This topic is locked and can not be replied to.