We just added the python binding for SunPinyin' SLM (statistical language model), pyslm, and several alternative utilities written by python. To build the extension, you need download/install cython. To build the pyslm extension on Solaris with SunStudio, you may need the following settings (seems that the distutils module on Solaris has some problems to set the compiler and flags properly):

$ export CC=/opt/SUNWspro/bin/CC
$ export LDFLAGS="-lCrun"

I referred to the tutorial "Wrapping C++ Classes in Pyrex/Cython" to write the extension. This article implicitly mentioned how to deal the reference parameter (I also figured it out by myself :)), e.g., if we have a new member function for Rectangle:

void getPosition (int &x, int &y) 

Then we could declare this member function in "pyx" file as:

ctypedef struct c_Rectangle "Rectangle":
    int x0, y0, x1, y1
    ... ...
    void getPosition (int x, int y)

This trick will cheat cython/pyrex to populate the arguments properly. This also works for the C-structure that has bit-fields.

评论:

发表一条评论:
该日志评论功能被禁用了。

This blog copyright 2009 by yongsun