Monday, July 5, 2010

What have I done...

...sa far :)
As you see I'm not really into blogging however I would like to share about the progress with PyPy - fast ctypes project.

The code lives in a branch at codespeak and you can simple take a look at:
https://codespeak.net/viewvc/pypy/branch/fast-ctypes/
or even better check it out:
svn co http://codespeak.net/svn/pypy/branch/fast-ctypes

What is already done?

I guess not too much :-) I've started a new Foreign Function Interface called jitffi which you can find in pypy/rlib/rjitffi.py. For object space go to pypy/module/jitffi/. It uses the PyPy JIT to call functions.

With this module we can simply load dynamic C libraries and call functions from the loaded library. There are some limitations such as all function arguments have to be the same type. Other limitation is that jitffi supports only int and float types (and void obviously) so far.

Here is a sample to see how we can use it:

import jitffi
lib = jitffi.CDLL('library_name.so')

func = lib.get('func_name1', ['int', 'int'], 'int')
func.call([1,2]) # return int

func = lib.get('func_name2', ['int'])
func.call([10]) # return None (as it's equivalent to C void)

This API is completely unstable and changes are made from time to time, or rather from commit to commit :-) The best way is to check appropriate tests to see the current API and how to use it.

What am I doing now?

The next step is to drop the limitation of same type of passing arguments. The problem is that the RPython lists can store only elements of the same type in one instance.
The idea is to fish the passed arguments from app-level and push it onto the stack. I'm working on it now.

Next? The PyPy JIT supports ints, floats and pointers. So, I will go to give a support for the latter.

This is it. The plan for the next week.

No comments:

Post a Comment