Multiple program defined types -- access from C?

Gordon McMillan gmcm at hypernet.com
Wed Jul 7 09:38:04 EDT 1999


Nathan Froyd wrote:
> I'm writing a program that needs a lot of program-defined types that
> are also exposed as python classes to the user. The problem is, I
> also need to access the innards of a lot of these classes from C.
> Are there any elegant ways to do this? It doesn't seem as though
> Python likes for class functions to be used from outside the C file
> they're defined in.

Python asks you to declare almost everything as file static to reduce 
the chance of name clashes when loaded dynamically in Unix (or maybe 
I should say non-Windows, where this is not a problem).

The "proper" way to make a C API available to other modules is to use 
a CObject (see Extending / Embedding section 1.12) to pass a void * 
around. If you're not trying to provide a C API to other extensions, 
you can probably get away with losing the "static", as long as you're 
careful about how you name your functions.

- Gordon




More information about the Python-list mailing list