~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/rpython/ootypesystem/module/ll_os.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from pypy.rpython.module.support import OOSupport
 
3
from pypy.rpython.module.ll_os import BaseOS
 
4
from pypy.rpython.ootypesystem import ootype
 
5
from pypy.rlib.rarithmetic import intmask
 
6
 
 
7
def _make_tuple(FIELDS):
 
8
    n = len(FIELDS)
 
9
    fieldnames = ['item%d' % i for i in range(n)]
 
10
    fields = dict(zip(fieldnames, FIELDS))
 
11
    return ootype.Record(fields)
 
12
 
 
13
STAT_RESULT = _make_tuple([ootype.Signed]*10)
 
14
PIPE_RESULT = _make_tuple([ootype.Signed]*2)
 
15
WAITPID_RESULT = _make_tuple([ootype.Signed]*2)
 
16
 
 
17
class Implementation(BaseOS, OOSupport):
 
18
    
 
19
    def ll_stat_result(stat0, stat1, stat2, stat3, stat4,
 
20
                       stat5, stat6, stat7, stat8, stat9):
 
21
        tup = ootype.new(STAT_RESULT)
 
22
        tup.item0 = intmask(stat0)
 
23
        tup.item1 = intmask(stat1)
 
24
        tup.item2 = intmask(stat2)
 
25
        tup.item3 = intmask(stat3)
 
26
        tup.item4 = intmask(stat4)
 
27
        tup.item5 = intmask(stat5)
 
28
        tup.item6 = intmask(stat6)
 
29
        tup.item7 = intmask(stat7)
 
30
        tup.item8 = intmask(stat8)
 
31
        tup.item9 = intmask(stat9)
 
32
        return tup
 
33
    ll_stat_result = staticmethod(ll_stat_result)
 
34
 
 
35
    def ll_os_read(cls, fd, count):
 
36
        return cls.to_rstr(os.read(fd, count))
 
37
    ll_os_read.suggested_primitive = True
 
38
 
 
39
    def ll_pipe_result(fd1, fd2):
 
40
        tup = ootype.new(PIPE_RESULT)
 
41
        tup.item0 = fd1
 
42
        tup.item1 = fd2
 
43
        return tup
 
44
    ll_pipe_result = staticmethod(ll_pipe_result)
 
45
 
 
46
    def ll_os_readlink(cls, path):
 
47
        return cls.to_rstr(os.readlink(path))
 
48
    ll_os_readlink.suggested_primitive = True
 
49
 
 
50
    def ll_waitpid_result(fd1, fd2):
 
51
        tup = ootype.new(WAITPID_RESULT)
 
52
        tup.item0 = fd1
 
53
        tup.item1 = fd2
 
54
        return tup
 
55
    ll_waitpid_result = staticmethod(ll_waitpid_result)