[IronPython] Announcement: Project to get some CPython C extensions running under IronPython

Curt Hagenlocher curt at hagenlocher.org
Wed Oct 17 18:45:50 CEST 2007

On 10/17/07, Paolo Molaro <lupus at ximian.com> wrote:
> 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.

I'm having trouble understanding what you mean by this.  Let's say I've got
an extension method that looks like this:

PyObject * ModifyColumns(PyObject * self, PyObject * args)
    PyObject * columns;
    if (!PyArg_ParseTuple(args, "O", &columns))
        return NULL;

    if (!PySequence_Check(columns))
        PyErr_SetString(PyExc_ValueError, "parameter must be a sequence");
        return NULL;

    PyObject * result = PyTuple_New(PySequence_Length(columns));
    for (int i = 0; i < PySequence_Length(columns); i++)
        PyObject * value = PySequence_GetItem(sequence, i);
        // Do something to value
        // And make sure you don't screw up the reference count
        PySequence_SetItem(result, i, value);

    return result;

In order to use this extension from IronPython, I need C implementations of
each of those API functions.  The PySequence_ methods should to be able to
understand CLR arrays or any other IEnumerable-like object.  I'm not sure
what PyTuple_New should return, but whatever it is will need to have
PyObject*-like semantics.

How does DllImport fit into this picture?  How can I avoid implementing all
these functions in C or C++?

Curt Hagenlocher
curt at hagenlocher.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20071017/3b7ad5be/attachment.html>

More information about the Ironpython-users mailing list