Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie has problem changing C char strings with Python/SWIG

Reply
Thread Tools

Newbie has problem changing C char strings with Python/SWIG

 
 
Rick Olson
Guest
Posts: n/a
 
      01-09-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
are immediate strings changing from "char *" to "const char *" ? Lynn McGuire C++ 8 08-10-2010 07:14 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
Problem- strcat with char and char indexed from char array aldonnelley@gmail.com C++ 3 04-20-2006 07:32 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments