complicated embedding question from newbie

Fred Clift fred at cs.byu.edu
Wed Aug 23 12:43:33 EDT 2000


Ok -- I have an existing C application with lots of complicated
data-structures, lots of legacy things I can't change, etc.

I want to embed python into this application.  I want data analysis and
modification to be done by calling python functions

(just finished my first fly-over of the embedding and extending chapters
of 'Programming Python').

My problem is that most of the data will need to be accessed from python
and I dont think it would be the best thing to send copies of all the
data into the function, and then perhaps parse output in C to know what
parts of the data to change.


So, running a C program, I want to call python functions that can call
c-functions in my current program, with access to the current state of
my C program.


I envision doing this by doing something like, instantiating a python
interpreter, somehow, wrapping up and encoding a pile of C function
pointers and passing them to the python interpreter.  Then I'd pass my
analysis scripts to python one at a time.  Those scripts call the right
subset of the C functions to get the data they need to do their work,
call some other C functions to change some of that data and then return
back into the original C function.

I have a lot of hard-coded C routines right now that I'm trying to
replace by interpreted python routines so I dont have to re-compile when
I want to tweak and test these analysis scripts.

I CANT move all my data into python and then have all the C routines get
it from there, and I haven't yet found the way I can have python access
data stored in the calling C program, without explicitly passing it
in...  I understand that  you can embed C routines in python, but they
dont have access to the same stack as the calling program, I think.

Anyone know how I can do this?  Bear in mind that I'm no python wiz
(yet) but that I'm not afraid of complicated work.  pointers in the
right direction would be greatly appreciated.


Fred Clift
fred at cs.byu.edu


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list