First question on extending Python...

John Machin sjmachin at lexicon.net
Fri Jun 9 18:45:48 EDT 2006


On 10/06/2006 8:32 AM, Redefined Horizons wrote:
> I still new to Python, and I've only dabbled in C, but I've got my
> first project I need to tackle that involves both languages. I was
> hoping to get some advice on how to proceed.
> 
> There is a third-party application that I need to work with. It is
> closed-source, but it exposes a C API. I want to wrap this C API so
> that it is available from Python. I have no ability to modify the C
> API of the third part application.
> 
> Do I the C functions that I wrap in an extensions module for Python
> need to be in a certian format? 

No.


> If so, I will have to write an
> intermediate DLL in C that wraps the third-party application and
> exports the functions in a form that Python can use.

No way. You need only *one* layer of glue.

> 
> Or can an extension module for Python wrap any C function?

I've never heard of a C function that couldn't be wrapped. If there were 
such a function, having more C code in a separate DLL wouldn't make it 
wrappable.

> If this is
> the case I think I can skip the intermediate C DLL.

I think so too.

> 
> Are there any advantages to using the intermediate DLL written in C in
> this particular case where I will not have ability to manipulate the C
> API of the third party application directly? (For example, if the
> third-party application developers are willing to call a "call-back"
> function that must be written in C, but not Python.

No advantages that I can see. Your C call-back function could then call 
a Python function if you really wanted to -- the 3rd-party devs don't 
need to know :-)

> Could the same
> extension module export both C functions and serve as a Python
> module?)

Yes.

Cheers,
John



More information about the Python-list mailing list