Efficient data flow between orthogonal C extensions?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Thu Jun 5 17:31:23 EDT 2003


In article <87znkwwmbg.fsf at smtp.gsi.de>, Pierre Schnizer wrote:
[snip]
>Perhaps I should have been more explicit. If I get your viewpoint correctly, I
>can answer: SWIG generally can do the job you described above. 
[snip]
>What I wanted to stress and what misled you, (I guess), was that SWIG does
>not help you to automatise writting a C callback, which will call the python
>function.

Ah. I see.

>(At least I do not know about ...).  For example f2py can parses the
>code of a Fortran ODE solver and will automatically generate a wrapper and a
>callback wrapper. Thus one can use it to integrate a function written in
>Python.

Yes, that does sound very useful...

>In the SWIG case you have to write the callback wrapper by hand. But
>as you want to use C Functions in both cases that is not too much of
>concern for you.

Well -- I do want to be able to write components both in C and Python,
so it is relevant.

>Perhaps a example. Consider the gsl root solver (partly taken from 
>http://pygsl.sf.net).
[snip]
>Here it is interesting to be able to integrate a python function.
>Therefore a C wrapper was written. This function is called by the gsl roots
>solver.

I see.

><snip>
> double 
> PyGSL_function_wrap(double x, void * params)
> {
[snip]
> }
><snip>
>
>On the entry side,

Sorry if I'm slow here -- but where would the 'entry side' be?

>there is an other wrapper which puts the callback and its arguments
>in the p struct and sets PyGSL_function_wrap as callback for the root
>solver. 

Can the PyGSL_function_wrap be used in place of a plain C function
(passed from Python)? In that case -- how does the solver know when to
pass the params and when not to etc.?

>I hope that cleared the point a bit what I wanted to express.

Yes, I think so -- at least, I think I get the general point, but I'm
not 100% clear on the detail... Maybe I should read the GSL code :]

Anyway, the case without using Python-implemented callbacks seems
quite clear. If SWIG does indeed do all the work, there really
shouldn't be much of a problem, I guess :)

>Regards
>	Pierre

-- 
Magnus Lie Hetland                "In this house we obey the laws of
http://hetland.org                 thermodynamics!"    Homer Simpson




More information about the Python-list mailing list