[pypy-svn] pypy default: posix.getgroups: now i'm allocating an array of gid_t also for the first call

berdario commits-noreply at bitbucket.org
Mon Jan 24 14:38:03 CET 2011


Author: Dario Bertini <berdario at gmail.com>
Branch: 
Changeset: r41256:6770e6a39633
Date: 2011-01-24 10:24 +0100
http://bitbucket.org/pypy/pypy/changeset/6770e6a39633/

Log:	posix.getgroups: now i'm allocating an array of gid_t also for the
	first call put the lltype.free inside a finally block

diff --git a/pypy/rpython/module/ll_os.py b/pypy/rpython/module/ll_os.py
--- a/pypy/rpython/module/ll_os.py
+++ b/pypy/rpython/module/ll_os.py
@@ -684,15 +684,19 @@
         c_getgroups = self.llexternal('getgroups',[rffi.INT, GP],rffi.INT)
 
         def getgroups_llimpl():
-            n = c_getgroups(0,s_None)
-            if n >= 0:
-                groups = lltype.malloc(GP.TO, n, flavor='raw')
-                n = c_getgroups(n,groups)
-                result = [g for g in groups]
+            groups = lltype.malloc(GP.TO, 0, flavor='raw')
+            try:
+                n = c_getgroups(0, groups)
+                if n >= 0:
+                    lltype.free(groups, flavor='raw')
+                    groups = lltype.malloc(GP.TO, n, flavor='raw')
+                    n = c_getgroups(n,groups)
+                    result = [g for g in groups]
+                    if n >= 0:
+                        return result
+                raise OSError(rposix.get_errno(), "os_getgroups failed")
+            finally:
                 lltype.free(groups, flavor='raw')
-                if n >= 0:
-                    return result
-            raise OSError(rposix.get_errno(), "os_getgroups failed")
 
         return extdef([],[self.GID_T],llimpl=getgroups_llimpl, export_name="ll_os.ll_getgroups")
 


More information about the Pypy-commit mailing list