[pypy-commit] pypy get/setpriority: translate to corresponding C code
nanjekye
pypy.commits at gmail.com
Mon Feb 27 06:39:53 EST 2017
Author: Joannah Nanjekye <nanjekyejoannah at gmail.com>
Branch: get/setpriority
Changeset: r90379:a36386624a08
Date: 2016-12-30 17:29 +0300
http://bitbucket.org/pypy/pypy/changeset/a36386624a08/
Log: translate to corresponding C code
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1605,29 +1605,6 @@
except OSError as e:
raise wrap_oserror(space, e)
- at unwrap_spec(program=int, identifier=int)
-def getpriority(space, program, identifier):
- """ getpriority(process, identifier) -> current_priority
-
- Get program scheduling priority.
- """
- try:
- returned_priority = os.getpriority(process, identifier)
- except OSError as e:
- raise wrap_oserror(space, e)
- return space.wrap(returned_priority)
-
- at unwrap_spec(program=int, identifier=int, priority=int)
-def setpriority(space, program, identifier, priority):
- """ setpriority(process, identifier)
-
- Set program scheduling priority.
- """
- try:
- os.setpriority(process, identifier, priority)
- except OSError as e:
- raise wrap_oserror(space, e)
-
@unwrap_spec(path='fsencode')
def chroot(space, path):
""" chroot(path)
@@ -1863,6 +1840,29 @@
except OSError as e:
raise wrap_oserror(space, e)
+ at unwrap_spec(program=int, identifier=int)
+def getpriority(space, program, identifier):
+ """ getpriority(process, identifier) -> int
+
+ Get program scheduling priority.
+ """
+ try:
+ returned_priority = rposix.getpriority(program, identifier)
+ except OSError as e:
+ raise wrap_oserror(space, e)
+ return space.wrap(returned_priority)
+
+ at unwrap_spec(program=int, identifier=int, priority=int)
+def setpriority(space, program, identifier, priority):
+ """ setpriority(process, identifier)
+
+ Set program scheduling priority.
+ """
+ try:
+ rposix.setpriority(program, identifier, priority)
+ except OSError as e:
+ raise wrap_oserror(space, e)
+
def declare_new_w_star(name):
if name in ('WEXITSTATUS', 'WSTOPSIG', 'WTERMSIG'):
@unwrap_spec(status=c_int)
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -852,15 +852,15 @@
def test_os_getpriority(self):
posix, os = self.posix, self.os
- assert os.getpriority(os.PRIO_PROCESS, os.getpid()) == posix.getpriority(os.PRIO_PROCESS, os.getpid())
+ assert os.getpriority(1,os.getpid()) == posix.getpriority(1,os.getpid())
def test_os_setpriority(self):
posix, os = self.posix, self.os
- result = posix.getpriority(os.PRIO_PROCESS, os.getpid())
- posix.setpriority(os.PRIO_PROCESS, os.getpid(), result + 1)
- new_result = posix.getpriority(os.PRIO_PROCESS, os.getpid())
- assert new_result == (result + 1)
-
+ orig_priority = posix.getpriority(1, os.getpid())
+ posix.setpriority(1, os.getpid(), orig_priority + 1)
+ new_result = posix.getpriority(1, os.getpid())
+ assert new_result == (orig_priority + 1)
+
def test_write_buffer(self):
os = self.posix
fd = os.open(self.path2 + 'test_write_buffer',
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1734,6 +1734,19 @@
def setresgid(rgid, egid, sgid):
handle_posix_error('setresgid', c_setresgid(rgid, egid, sgid))
+ c_getpriority = external('getpriority', [rffi.INT, rffi.INT], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO)
+ c_setpriority = external('setpriority', [rffi.INT, rffi.INT, rffi.INT], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO)
+
+ @replace_os_function('getpriority')
+ def getpriority(program, identifier):
+ return handle_posix_error('getpriority', c_getpriority(program, identifier))
+
+ @replace_os_function('setpriority')
+ def setpriority(program, identifier, priority):
+ handle_posix_error('setpriority', c_setpriority(program, identifier, priority))
+
#___________________________________________________________________
c_chroot = external('chroot', [rffi.CCHARP], rffi.INT,
More information about the pypy-commit
mailing list