[IronPython] My takes on C Extensions for IronPython

Seo Sanghyeon sanxiyn at gmail.com
Thu Oct 18 02:42:05 CEST 2007

The discussion is getting very confusing, so here are some of my takes
on the issues.

On the issue of P/Invoke declarations for Python/C API, Paolo Molaro

"The python API requires a couple dozen structure definitions plus a
few dozen dllimport declarations. This can be about 200 lines of
trivial to write declarative stuff."

It's certainly more than 200 lines, and it's not completely trivial
because some parts of Python/C API are C macros, not C functions.
(Reference counting is the most important, but also getting
type(=vtable) of Python objects and like.)

The good news is that this part is already developed, debugged, and
pretty much finished -- for Python 2.3 to 2.6, and for wide and narrow
unicode builds of Python. Get it here (~ 1600 lines):

Assuming that ZPL (which is OSI-certified) is okay, it would be
strange not to use this.

On the issue of compiling C or C++ to CLI, Keith J. Famer wrote:

"My impression was that they're working under the assumption that you
cannot get C++ code to compile to pure managed (False, use C++/CLI as
recommended on the Mono site), and that it must *compile* under Mono
(laudable, but I doubt it's necessary -- I've never bothered to
recompile the Python Libraries)."

Readers not familiar with the issue should read Mono documentation

I understand MC++ or Managed C++ is used to refer related
technologies, but in the narrow sense it is a compiler that shipped
with .NET 1.x which produced mix of managed and x86 code. I
believe .NET 2.x compiler, i.e. C++/CLI is what is currently

It would be nice to be able to compile without Microsoft tools, but I
don't think it's essential. If assembly compiled with C++/CLI /
clr:pure can be made to run on Mono that's fine.

Also Mono page doesn't mention this, but GCC backend to emit CLI code
*is* complete and working. It's available right now from GCC SVN. But
it's yet another project, not Google Summer of Code attempts. This
project is backed by STMicroelectronics, a big corporation, probably
for its own use.

Remember, Mono doesn't need to be the sole provider of non-Microsoft
CLI tools. :) I believe GCC/CLI can be made to help this project.

Okay, enough said for this mail...

Seo Sanghyeon

More information about the Ironpython-users mailing list