Newbie has problem changing C char strings with Python/SWIG

Discussion in 'Python' started by Rick Olson, Jan 9, 2004.

  1. Rick Olson

    Rick Olson Guest

    I've tried posting this on the SWIG listserve, but traffic has been
    slow there and I haven't had a reply. If this isn't the correct
    forum, please suggest another. Thanks.

    I'm trying to use python as the interface for an existing program
    written in C. I've gotten many things to work including using cvar to
    assign values to long and double variables in the C module from
    python. I'm having trouble using it to assign strings. I've reduced
    the problem to the following .c and .i files, and a sample idlefork
    session:
    --------------------
    example.c
    char *eval_name;
    void define_globals()
    { eval_name = "Bob";
    }
    --------------------
    example.i
    %module example
    %{
    %}
    extern void define_globals();
    extern char *eval_name;
    ---------------------
    IDLEfork 0.9b1
    >>> import example
    >>> example.define_globals()
    >>> example.cvar.eval_name

    'Bob'
    >>> example.cvar.eval_name='Tony'
    >>> ==== RESTART ================================


    I seem to be able to use Python invoke the C function that assigns
    "Bob" to the variable eval_name, but when I try to assign a new name
    ('Tony') the idlefork shell restarts.

    I've combed the docs and the archives at swig.org, but I didn't see
    this ddressed anywhere. I strongly suspect that I looked right at
    it, but didn't
    recognize it at the time. This leads to 2 questions:

    1) How do I perofrm the desired assignment?
    2) Where was the answer in the docs so I can look at it and try to
    understand how I overlooked it.

    Thanks in advance--
    Rick Olson
    Rick Olson, Jan 9, 2004
    #1
    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. Chris

    SWIG char** to Python list

    Chris, Apr 29, 2005, in forum: Python
    Replies:
    0
    Views:
    526
    Chris
    Apr 29, 2005
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,043
    Ian Collins
    May 9, 2006
  3. Replies:
    3
    Views:
    732
  4. ObiWanKinobi
    Replies:
    0
    Views:
    701
    ObiWanKinobi
    Jun 6, 2010
  5. Lynn McGuire
    Replies:
    8
    Views:
    692
    Lynn McGuire
    Aug 10, 2010
Loading...

Share This Page