swig problem

Discussion in 'Ruby' started by dominic sisneros, Apr 2, 2004.

  1. I am trying to wrap a function that either takes a char * or NULL
    How would I wrap this in swig?

    The c version accepts a conts char * or NULL

    librdf_node* librdf_new_node_from_blank_identifier(librdf_world *world,
    const char * identifier);

    I do a typemap as follows

    I tried this but am still getting a TypeError converting Nil to String

    %typemap(ruby,in) const char *identifier {
    if $input == Qnil{
    $1 == NULL;
    else
    $1 = STR2CSTR($input);
    }
    }
     
    dominic sisneros, Apr 2, 2004
    #1
    1. Advertising

  2. dominic sisneros wrote:
    > I do a typemap as follows
    >
    > I tried this but am still getting a TypeError converting Nil to String
    >
    > %typemap(ruby,in) const char *identifier {
    > if $input == Qnil{
    > $1 == NULL;
    > else
    > $1 = STR2CSTR($input);
    > }
    > }


    Rerun swig and recompile your extension before trying again ;)

    I can see you didn't because there are 2 syntax errors (and 1 semantic
    error) in your typemap. Your compiler would have caught the 2 syntax
    ones. Or maybe you just didn't notice the error messages.

    - C requires that you parenthesize the test expression after the "if"
    - Your "else" has no previous "if" (removing the inner braces will help)
    - "$1 == NULL" doesn't do anything.

    Apart from these errors, your typemap is correct and your code will work
    once you correct them.

    Tobias
     
    Tobias Peters, Apr 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Schmidt

    SWIG, MinGW, and Python 2.3 problem

    Phil Schmidt, Sep 10, 2003, in forum: Python
    Replies:
    0
    Views:
    549
    Phil Schmidt
    Sep 10, 2003
  2. Alfonso Cepeda Caballos,,,

    Problem using swig

    Alfonso Cepeda Caballos,,,, Nov 4, 2003, in forum: Python
    Replies:
    0
    Views:
    304
    Alfonso Cepeda Caballos,,,
    Nov 4, 2003
  3. S Green
    Replies:
    1
    Views:
    892
    Lyle Johnson
    Nov 26, 2003
  4. Rick Olson
    Replies:
    0
    Views:
    454
    Rick Olson
    Jan 9, 2004
  5. Uwe Mayer

    sip problem (was: swig problem)

    Uwe Mayer, Feb 16, 2004, in forum: Python
    Replies:
    0
    Views:
    310
    Uwe Mayer
    Feb 16, 2004
Loading...

Share This Page