[pypy-dev] Mixed modules for both PyPy and CPython

Armin Rigo arigo at tunes.org
Sat Apr 15 18:34:29 CEST 2006


Re-hi,

On Wed, Apr 12, 2006 at 12:29:48PM +0200, Armin Rigo wrote:
>     class CPyObjSpace:
> 
>         def newint(self, intval):
>             return ctypes.pydll.PyInt_FromLong(intval)
> 
>         def add(self, w_1, w_2):
>             return ctypes.pydll.PyNumber_Add(w_1, w_2)
>         ...

Correction here.  It's not 'ctypes.pydll' -- this one is an object used
to load other DLLs following the CPython calling convensions.  It's
'ctypes.pythonapi' instead, and it works on standard Linux installations
as well.  Just try:

    >>> from ctypes import *
    >>> pythonapi.PyNumber_Add.restype = py_object
    >>> pythonapi.PyNumber_Add(py_object(5), py_object(6))
    11

(The result is 11 instead of py_object(11) because ctypes does automatic
unwrapping of some return types.)


A bientot,

Armin



More information about the Pypy-dev mailing list