Newbie has problem changing C char strings with Python/SWIG

R

Rick Olson

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
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top