[IronPython] [python] Re: Announcement: Project to get someCPython C extensions running under IronPython
Curt Hagenlocher
curt at hagenlocher.org
Thu Oct 18 00:22:03 CEST 2007
On 10/17/07, Joe Mason <joe at notcharles.ca> wrote:
>
> On 10/17/07, Keith J. Farmer <kfarmer at thuban.org> wrote:
> > Forgive my non-C-ness (it's been a long time since I wrote a native
> module
> > for Python), but aren't you now buying into a major re-implementation of
> all
> > the native Python standard library into C#?
>
> Couldn't the C/C# API just use IronPython objects and methods to
> "implement" the Python standard library?
Yes, that would be the idea.
I think it's best when thinking about the architecture to have a specific
example to refer to. With that in mind, I'm going to repeat some code I
wrote earlier in the thread (with a few modifications).
PyObject * ReverseSequence(PyObject * self, PyObject * args)
{
PyObject * columns;
if (!PyArg_ParseTuple(args, "O", &columns))
{
return NULL;
}
if (!PySequence_Check(columns))
{
PyErr_SetString(PyExc_ValueError, "must be a sequence");
return NULL;
}
int length = PySequence_Length(columns);
PyObject * result = PyTuple_New(length);
for (int i = 0; i < length; i++)
{
PyObject * value = PySequence_GetItem(sequence, i);
// Don't remember if I need to INCREF value
PySequence_SetItem(result, length - i - 1, value);
}
return result;
}
Obviously, this isn't a "real-world" example, but it does show a few
requirements for the compatibility layer.
1) The code expects a sequence. What kind of data should we be allowed to
pass to it from IronPython?
2) The code returns a "tuple". How will this tuple be translated into a CLR
object for consumption by IronPython?
--
Curt Hagenlocher
curt at hagenlocher.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20071017/c5173de8/attachment.html>
More information about the Ironpython-users
mailing list