extending Python with C anywhere (was Re: Extending Python with C/C++ on a win32 platform)

John Machin machin_john_888 at hotmail.com
Wed May 23 18:32:23 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message news:<9ege3v02q8p at enews1.newsguy.com>...

[snip]
> Still, if you DO want to use the C-level API, it's not rocket
> science... just a documentation problem.  Building stuff under
> windows has become wonderfully easy thanks to the distutils!-)

Astonishingly easy, even with the Borland compiler --- congrats to the
distutils developers!

> Here's a toy-level example, fully portable to VC++ and
> all other Python-supported platforms.  It's an extension
[snip]
> But the functionality isn't very important -- the key
> is, once having a correct, portable "bill.c" file, how
> do you build it _everywhere_?
> 
[snip]
> 
> There -- a single command did the build AND
> installed the .pyd into our \Python21 directory.
> Ain't it cool?-)
> 
> And now we test (we should really have a unit test
> script of course...:-):

Radically kool, dood ... but "Test before install" might be a
preferred order for some folks. You might even find some wrinklies who
would say "back-up before install".

[snip]
> ::: bill.c
[snip]
>     if(!value) { // deletion

C? Portable? 

OK, enough nit-picking. The other 99% was good value. I'd just like to
add a recommendation to all newbie extension craftspersons:

There is a large quantity of solid well-written robust working C-coded
extensions out there. You don't have to look much further than the
Python source itself, in the modules and objects directories. Think of
a Python construct that's structurally similar to what you want to do,
then go find where it's implemented. For example, you want to parse a
string and return a list of bits and pieces? Study the implementation
of the split method in stringobject.c. The next place to look would be
in the Vaults of Parnassus ... lots of good stuff there too.



More information about the Python-list mailing list