[pypy-dev] Writing os.pipe() using ctypes

Stephen Thorne stephen at thorne.id.au
Thu Jul 6 08:43:12 CEST 2006


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?


More information about the Pypy-dev mailing list