Efficient data flow between orthogonal C extensions?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Thu Jun 5 08:03:24 EDT 2003


In article <6qfzmokc1t.fsf at salmakis.intevation.de>, Bernhard Herzog wrote:
[snip]
>I'm not sure how similar it is to what Magnus wants to do, but at least
>the C-API handling might be an example.

Indeed.

>The basic approach taken to communicate a C-API from one dynamically
>loaded module to another is that the streamfilter module as an attribute
>called Filter_Functions which holds a PyCObject containing a pointer to
>a struct with function pointers. The pstokenize module imports the
>streamfilter module, extracts the struct and then calls the functions.

Somewhat similar to the approach in the standard docs, then, except
that you don't #include the .h-file of each extension...? (I'll look
into the source.)

>The approach is basically the same as in cStringIO in the Python sources
>(see Include/cStringIO.h and Modules/cStringIO.c.

Yeah, but this is more or less what I started out with (I think?) --
your C code needs to contain #import statements and call to macros to
initialize the imported C code (such as PycString_IMPORT in this
case)... The components themselves can't do this, since I want them to
be orthogonal, and I don't see how the coordinating framework can
either, since I want the components to be dynamically
available/loadable (i.e. orthogonal of the framework, basically).

Maybe I'm missing an important part of the functionality here... Is it
possible to only keep a generic version of these declarations, and to
store the specific implementations as PyCObjects? Is that what you do
in Sketch?

Basically, what I would like to do is have all C components totally
ignorant of each other and only receive info about the "outside world"
from the Python interpreter (probably in the form of PyCObjects).

I would also like to make Python components and C components
polymorphically equivalent, but that shouldn't be hard with some added
Python magic on top of things ;)

>PyGTK also does somethng like this.

OK. Thanks.

>   Bernhard

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