Re: [pypy-dev] [pypy-svn] r79938 - in pypy/trunk/pypy: module/posix module/posix/test rpython/module translator/c/test
![](https://secure.gravatar.com/avatar/bfc96d2a02d9113edb992eb96c205c5a.jpg?s=120&d=mm&r=g)
Do we *really* need those functions available on RPython level? On Thu, Dec 9, 2010 at 7:30 PM, <arigo@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-svn@codespeak.net http://codespeak.net/mailman/listinfo/pypy-svn
![](https://secure.gravatar.com/avatar/cd2e442c42c95ed534e4197df4300222.jpg?s=120&d=mm&r=g)
2010/12/9 Maciej Fijalkowski <fijall@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
![](https://secure.gravatar.com/avatar/5b37e6b4ac97453e4ba9dba37954cf79.jpg?s=120&d=mm&r=g)
Hi, On Fri, Dec 10, 2010 at 2:45 AM, Benjamin Peterson <benjamin@python.org> wrote:
2010/12/9 Maciej Fijalkowski <fijall@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.
participants (3)
-
Armin Rigo
-
Benjamin Peterson
-
Maciej Fijalkowski