Re: [pypy-dev] [pypy-svn] r79938 - in pypy/trunk/pypy: module/posix module/posix/test rpython/module translator/c/test

2010-12-10 Thread Armin Rigo
Hi,

On Fri, Dec 10, 2010 at 2:45 AM, Benjamin Peterson benja...@python.org wrote:
 2010/12/9 Maciej Fijalkowski fij...@gmail.com:
 Do we *really* need those functions available on RPython level?

 Even if we don't, I'd say the consistency is nice, rather than having
 ll implementations all over creation.

Agreed.  Consistency is probably better than having pypy/module/posix
be half written in the way it is now and half written in a
lltype-specific way.


A bientôt,

Armin.
___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev


Re: [pypy-dev] [pypy-svn] r79938 - in pypy/trunk/pypy: module/posix module/posix/test rpython/module translator/c/test

2010-12-09 Thread Maciej Fijalkowski
Do we *really* need those functions available on RPython level?

On Thu, Dec 9, 2010 at 7:30 PM,  ar...@codespeak.net wrote:
 Author: arigo
 Date: Thu Dec  9 18:30:33 2010
 New Revision: 79938

 Modified:
   pypy/trunk/pypy/module/posix/__init__.py
   pypy/trunk/pypy/module/posix/interp_posix.py
   pypy/trunk/pypy/module/posix/test/test_posix2.py
   pypy/trunk/pypy/rpython/module/ll_os.py
   pypy/trunk/pypy/translator/c/test/test_extfunc.py
 Log:
 Implement os.getloadavg().  (Phew, we really need to edit files in all
 corners of the world for this...)


 Modified: pypy/trunk/pypy/module/posix/__init__.py
 ==
 --- pypy/trunk/pypy/module/posix/__init__.py    (original)
 +++ pypy/trunk/pypy/module/posix/__init__.py    Thu Dec  9 18:30:33 2010
 @@ -111,6 +111,8 @@
         interpleveldefs['sysconf_names'] = 'space.wrap(os.sysconf_names)'
     if hasattr(os, 'ttyname'):
         interpleveldefs['ttyname'] = 'interp_posix.ttyname'
 +    if hasattr(os, 'getloadavg'):
 +        interpleveldefs['getloadavg'] = 'interp_posix.getloadavg'

     for name in ['setsid', 'getuid', 'geteuid', 'getgid', 'getegid', 'setuid',
                  'seteuid', 'setgid', 'setegid', 'getpgrp', 'setpgrp',

 Modified: pypy/trunk/pypy/module/posix/interp_posix.py
 ==
 --- pypy/trunk/pypy/module/posix/interp_posix.py        (original)
 +++ pypy/trunk/pypy/module/posix/interp_posix.py        Thu Dec  9 18:30:33 
 2010
 @@ -963,6 +963,17 @@
     return space.w_None
  chown.unwrap_spec = [ObjSpace, str, c_nonnegint, c_nonnegint]

 +def getloadavg(space):
 +    try:
 +        load = os.getloadavg()
 +    except OSError, e:
 +        raise OperationError(space.w_OSError,
 +                             space.wrap(Load averages are unobtainable))
 +    return space.newtuple([space.wrap(load[0]),
 +                           space.wrap(load[1]),
 +                           space.wrap(load[2])])
 +getloadavg.unwrap_spec = [ObjSpace]
 +
  if _WIN:
     from pypy.rlib import rwin32


 Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
 ==
 --- pypy/trunk/pypy/module/posix/test/test_posix2.py    (original)
 +++ pypy/trunk/pypy/module/posix/test/test_posix2.py    Thu Dec  9 18:30:33 
 2010
 @@ -521,6 +521,14 @@
                 assert os.WIFEXITED(status)
                 assert os.WEXITSTATUS(status) == exit_status

 +    if hasattr(os, 'getloadavg'):
 +        def test_os_getloadavg(self):
 +            os = self.posix
 +            l0, l1, l2 = os.getloadavg()
 +            assert type(l0) is float and l0 = 0.0
 +            assert type(l1) is float and l0 = 0.0
 +            assert type(l2) is float and l0 = 0.0
 +
     if hasattr(os, 'fsync'):
         def test_fsync(self):
             os = self.posix

 Modified: pypy/trunk/pypy/rpython/module/ll_os.py
 ==
 --- pypy/trunk/pypy/rpython/module/ll_os.py     (original)
 +++ pypy/trunk/pypy/rpython/module/ll_os.py     Thu Dec  9 18:30:33 2010
 @@ -730,6 +730,22 @@
         return extdef([traits.str, int, int], int, traits.ll_os_name('open'),
                       llimpl=os_open_llimpl, oofakeimpl=os_open_oofakeimpl)

 +   �...@registering_if(os, 'getloadavg')
 +    def register_os_getloadavg(self):
 +        AP = rffi.CArrayPtr(lltype.Float)
 +        c_getloadavg = self.llexternal('getloadavg', [AP, rffi.INT], 
 rffi.INT)
 +
 +        def getloadavg_llimpl():
 +            load = lltype.malloc(AP.TO, 3, flavor='raw')
 +            r = c_getloadavg(load, 3)
 +            result_tuple = load[0], load[1], load[2]
 +            lltype.free(load, flavor='raw')
 +            if r != 3:
 +                raise OSError
 +            return result_tuple
 +        return extdef([], (float, float, float),
 +                      ll_os.ll_getloadavg, llimpl=getloadavg_llimpl)
 +
  # --- os.read ---

     @registering(os.read)

 Modified: pypy/trunk/pypy/translator/c/test/test_extfunc.py
 ==
 --- pypy/trunk/pypy/translator/c/test/test_extfunc.py   (original)
 +++ pypy/trunk/pypy/translator/c/test/test_extfunc.py   Thu Dec  9 18:30:33 
 2010
 @@ -755,3 +755,13 @@
         for i in range(5):
             res = func(i)
             assert res == os.uname()[i]
 +
 +if hasattr(os, 'getloadavg'):
 +    def test_os_getloadavg():
 +        def does_stuff():
 +            a, b, c = os.getloadavg()
 +            print a, b, c
 +            return a + b + c
 +        f = compile(does_stuff, [])
 +        res = f()
 +        assert type(res) is float and res = 0.0
 ___
 pypy-svn mailing list
 pypy-...@codespeak.net
 

Re: [pypy-dev] [pypy-svn] r79938 - in pypy/trunk/pypy: module/posix module/posix/test rpython/module translator/c/test

2010-12-09 Thread Benjamin Peterson
2010/12/9 Maciej Fijalkowski fij...@gmail.com:
 Do we *really* need those functions available on RPython level?

Even if we don't, I'd say the consistency is nice, rather than having
ll implementations all over creation.



-- 
Regards,
Benjamin
___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev