Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r67895:d1bb8acdd365 Date: 2013-11-09 15:42 +0100 http://bitbucket.org/pypy/pypy/changeset/d1bb8acdd365/
Log: os.tcgetpgrp(), os.tcsetpgrp() diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py --- a/pypy/module/posix/__init__.py +++ b/pypy/module/posix/__init__.py @@ -156,7 +156,7 @@ 'seteuid', 'setgid', 'setegid', 'getgroups', 'getpgrp', 'setpgrp', 'getppid', 'getpgid', 'setpgid', 'setreuid', 'setregid', 'getsid', 'setsid', 'fstatvfs', 'statvfs', - 'setgroups', 'initgroups']: + 'setgroups', 'initgroups', 'tcgetpgrp', 'tcsetpgrp']: if hasattr(os, name): interpleveldefs[name] = 'interp_posix.%s' % (name,) # not visible via os, inconsistency in nt: 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 @@ -1121,6 +1121,29 @@ raise wrap_oserror(space, e) return space.w_None +@unwrap_spec(fd=c_int) +def tcgetpgrp(space, fd): + """ tcgetpgrp(fd) -> pgid + + Return the process group associated with the terminal given by a fd. + """ + try: + pgid = os.tcgetpgrp(fd) + except OSError, e: + raise wrap_oserror(space, e) + return space.wrap(pgid) + +@unwrap_spec(fd=c_int, pgid=c_gid_t) +def tcsetpgrp(space, fd, pgid): + """ tcsetpgrp(fd, pgid) + + Set the process group associated with the terminal given by a fd. + """ + try: + os.tcsetpgrp(fd, pgid) + except OSError, e: + raise wrap_oserror(space, e) + def declare_new_w_star(name): if name in RegisterOs.w_star_returning_int: @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 @@ -630,6 +630,16 @@ os = self.posix raises(OSError, os.initgroups, "crW2hTQC", 100) + if hasattr(os, 'tcgetpgrp'): + def test_os_tcgetpgrp(self): + os = self.posix + raises(OSError, os.tcgetpgrp, 9999) + + if hasattr(os, 'tcsetpgrp'): + def test_os_tcsetpgrp(self): + os = self.posix + raises(OSError, os.tcsetpgrp, 9999, 1) + if hasattr(os, 'getpgid'): def test_os_getpgid(self): os = self.posix diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py --- a/rpython/rtyper/module/ll_os.py +++ b/rpython/rtyper/module/ll_os.py @@ -129,10 +129,6 @@ ('tms_cutime', rffi.INT), ('tms_cstime', rffi.INT)]) - GID_T = platform.SimpleType('gid_t', rffi.INT) - #TODO right now is used only in getgroups, may need to update other - #functions like setgid - # For now we require off_t to be the same size as LONGLONG, which is the # interface required by callers of functions that thake an argument of type # off_t @@ -693,7 +689,7 @@ @registering_if(os, 'getgroups') def register_os_getgroups(self): - GP = rffi.CArrayPtr(self.GID_T) + GP = rffi.CArrayPtr(rffi.PID_T) c_getgroups = self.llexternal('getgroups', [rffi.INT, GP], rffi.INT) def getgroups_llimpl(): @@ -715,7 +711,7 @@ @registering_if(os, 'setgroups') def register_os_setgroups(self): - GP = rffi.CArrayPtr(self.GID_T) + GP = rffi.CArrayPtr(rffi.PID_T) c_setgroups = self.llexternal('setgroups', [rffi.SIZE_T, GP], rffi.INT) def setgroups_llimpl(list): @@ -723,7 +719,7 @@ groups = lltype.malloc(GP.TO, n, flavor='raw') try: for i in range(n): - groups[i] = rffi.cast(self.GID_T, list[i]) + groups[i] = rffi.cast(rffi.PID_T, list[i]) n = c_setgroups(rffi.cast(rffi.SIZE_T, n), groups) finally: lltype.free(groups, flavor='raw') @@ -736,10 +732,10 @@ @registering_if(os, 'initgroups') def register_os_initgroups(self): c_initgroups = self.llexternal('initgroups', - [rffi.CCHARP, self.GID_T], rffi.INT) + [rffi.CCHARP, rffi.PID_T], rffi.INT) def initgroups_llimpl(user, group): - n = c_initgroups(user, rffi.cast(self.GID_T, group)) + n = c_initgroups(user, rffi.cast(rffi.PID_T, group)) if n != 0: raise OSError(rposix.get_errno(), "os_initgroups failed") @@ -781,6 +777,35 @@ else: return self.extdef_for_os_function_accepting_0int(name) + @registering_if(os, 'tcgetpgrp') + def register_os_tcgetpgrp(self): + c_tcgetpgrp = self.llexternal('tcgetpgrp', [rffi.INT], rffi.PID_T) + + def c_tcgetpgrp_llimpl(fd): + res = c_tcgetpgrp(rffi.cast(rffi.INT, fd)) + res = rffi.cast(lltype.Signed, res) + if res == -1: + raise OSError(rposix.get_errno(), "tcgetpgrp failed") + return res + + return extdef([int], int, llimpl=c_tcgetpgrp_llimpl, + export_name='ll_os.ll_os_tcgetpgrp') + + @registering_if(os, 'tcsetpgrp') + def register_os_tcsetpgrp(self): + c_tcsetpgrp = self.llexternal('tcsetpgrp', [rffi.INT, rffi.PID_T], + rffi.INT) + + def c_tcsetpgrp_llimpl(fd, pgrp): + res = c_tcsetpgrp(rffi.cast(rffi.INT, fd), + rffi.cast(rffi.PID_T, pgrp)) + res = rffi.cast(lltype.Signed, res) + if res == -1: + raise OSError(rposix.get_errno(), "tcsetpgrp failed") + + return extdef([int, int], None, llimpl=c_tcsetpgrp_llimpl, + export_name='ll_os.ll_os_tcsetpgrp') + @registering_if(os, 'getppid') def register_os_getppid(self): return self.extdef_for_os_function_returning_int('getppid') diff --git a/rpython/rtyper/module/test/test_posix.py b/rpython/rtyper/module/test/test_posix.py --- a/rpython/rtyper/module/test/test_posix.py +++ b/rpython/rtyper/module/test/test_posix.py @@ -225,3 +225,24 @@ return 0 res = self.interpret(f, []) assert res == 1 + + if hasattr(os, 'tcgetpgrp'): + def test_tcgetpgrp(self): + def f(fd): + try: + return os.tcgetpgrp(fd) + except OSError: + return 42 + res = self.interpret(f, [9999]) + assert res == 42 + + if hasattr(os, 'tcsetpgrp'): + def test_tcsetpgrp(self): + def f(fd, pgrp): + try: + os.tcsetpgrp(fd, pgrp) + except OSError: + return 1 + return 0 + res = self.interpret(f, [9999, 1]) + assert res == 1 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit