[pypy-dev] Writing os.pipe() using ctypes
Amaury Forgeot d'Arc
amauryfa at gmail.com
Thu Jul 6 11:43:32 CEST 2006
Hello,
2006/7/6, Stephen Thorne <stephen at thorne.id.au>:
> Hi,
>
> I've been having fun this week trying to get twisted's unit tests running on top of pypy. This has the dual goals of getting twisted to run on a funky platform like pypy, and being able to give pypy a bit of a run around the yard. I have to report this is going "better than expected". I've already used rhymes's fcntl implementation and had to extend the posix module, I intend to do a diff once I get everything sorted.
>
> I have a problem with rpython translation of my implementation of posix.pipe(). I have other ctypes implementations of functions (such as posix.access()) which work okay, but I'm having trouble with this particular case.
>
> man 2 pipe says that I use it like this:
>
> int pipe(int filedes[2]);
>
> My implementation looks like:
>
> fd_arr = c_int * 2
> def pipe(space):
> fds = fd_arr()
> fds[0] = 0
> fds[1] = 0
> if libc.pipe(fds):
> raise makeOSError(space)
> return space.wrap((fds[0], fds[1]))
> pipe.unwrap_spec = [ObjSpace]
>
> And the error I get from time {{{python translate.py --text --batch standalone --thread}}} is:
> [translation:ERROR] Exception': unexpected prebuilt constant: <slot wrapper '__init__' of '_ctypes.Array' objects>
> [translation:ERROR] .. v0 = simple_call((ArrayType c_long_Array_2))
> [translation:ERROR] Processing block:
> [translation:ERROR] block at 3 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'>
> [translation:ERROR] in (pypy.module.posix.ctypes_posix:43)pipe
> [translation:ERROR] containing the following operations:
> [translation:ERROR] v0 = simple_call((ArrayType c_long_Array_2))
> [translation:ERROR] v1 = setitem(v0, (0), (0))
> [translation:ERROR] v2 = setitem(v0, (1), (0))
> [translation:ERROR] v3 = getattr((<CDLL '/usr/lib/libc...20a89f0>), ('pipe'))
> [translation:ERROR] v4 = simple_call(v3, v0)
> [translation:ERROR] v5 = is_true(v4)
> [translation:ERROR] --end--
>
> I've tried a bunch of ways of initialising the 'fds' object as to not make it a 'prebuilt constant', fds = fd_arr(0,0), creating fd_arr dynamically, fd_arr(zero, zero), etc. And I simply cannot seem to get rid of this exception.
>
> So, any ideas as to how I go about making this work?
>
> Stephen.
> _______________________________________________
> pypy-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-dev
>
It seems that translate.py does not "register" annotation for rctypes objects.
In a previous mail I suggested to add
import pypy.rpython.rctypes.implementation
in pypy/translator/goal/translate.py and translation seems to go further.
(I'm running
translate.py standalone --usemodules=_demo
after I added your code in demo.py)
Unfortunately the complete translation takes too much memory for the
machine I'm currently working on, so I could not test completely.
And since its a Windows box, I had to remove the libc.pipe call completely...
Hope this helps.
It seems that many people are interested in the new rctypes way to
create modules...
--
Amaury Forgeot d'Arc
More information about the Pypy-dev
mailing list