Author: Amaury Forgeot d'Arc <[email protected]>
Branch: more-rposix
Changeset: r74382:cd2c5d61bf3a
Date: 2014-11-07 17:52 +0100
http://bitbucket.org/pypy/pypy/changeset/cd2c5d61bf3a/

Log:    Port os.confstr &co

diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -837,3 +837,56 @@
 
 #___________________________________________________________________
 
+c_sysconf = external('sysconf', [rffi.INT], rffi.LONG)
+c_fpathconf = external('fpathconf', [rffi.INT, rffi.INT], rffi.LONG)
+c_pathconf = external('pathconf', [rffi.CCHARP, rffi.INT], rffi.LONG)
+c_confstr = external('confstr',
+                     [rffi.INT, rffi.CCHARP, rffi.SIZE_T], rffi.SIZE_T)
+
+@replace_os_function('sysconf')
+def sysconf(value):
+    set_errno(0)
+    res = c_sysconf(i)
+    if res == -1:
+        errno = get_errno()
+        if errno != 0:
+            raise OSError(errno, "sysconf failed")
+    return res
+
+@replace_os_functions('fpathconf')
+def fpathconf(fd, value):
+    rposix.set_errno(0)
+    res = c_fpathconf(fd, value)
+    if res == -1:
+        errno = rposix.get_errno()
+        if errno != 0:
+            raise OSError(errno, "fpathconf failed")
+    return res
+
+@replace_os_function('pathconf')
+def pathconf(path, value):
+    rposix.set_errno(0)
+    res = c_pathconf(_as_bytes0(path), value)
+    if res == -1:
+        errno = rposix.get_errno()
+        if errno != 0:
+            raise OSError(errno, "pathconf failed")
+    return res
+
+@replace_os_function('confstr')
+def confstr(value):
+    rposix.set_errno(0)
+    n = c_confstr(value, lltype.nullptr(rffi.CCHARP.TO), 0)
+    if n > 0:
+        buf = lltype.malloc(rffi.CCHARP.TO, n, flavor='raw')
+        try:
+            c_confstr(value, buf, n)
+            return rffi.charp2strn(buf, n)
+        finally:
+            lltype.free(buf, flavor='raw')
+    else:
+        errno = rposix.get_errno()
+        if errno != 0:
+            raise OSError(errno, "confstr failed")
+        return None
+
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
@@ -235,76 +235,6 @@
         return extdef([int], int, llimpl=c_func_llimpl,
                       export_name='ll_os.ll_os_' + name)
 
-    @registering_if(os, 'sysconf')
-    def register_os_sysconf(self):
-        c_sysconf = self.llexternal('sysconf', [rffi.INT], rffi.LONG)
-
-        def sysconf_llimpl(i):
-            rposix.set_errno(0)
-            res = c_sysconf(i)
-            if res == -1:
-                errno = rposix.get_errno()
-                if errno != 0:
-                    raise OSError(errno, "sysconf failed")
-            return res
-        return extdef([int], int, "ll_os.ll_sysconf", llimpl=sysconf_llimpl)
-
-    @registering_if(os, 'fpathconf')
-    def register_os_fpathconf(self):
-        c_fpathconf = self.llexternal('fpathconf',
-                                      [rffi.INT, rffi.INT], rffi.LONG)
-
-        def fpathconf_llimpl(fd, i):
-            rposix.set_errno(0)
-            res = c_fpathconf(fd, i)
-            if res == -1:
-                errno = rposix.get_errno()
-                if errno != 0:
-                    raise OSError(errno, "fpathconf failed")
-            return res
-        return extdef([int, int], int, "ll_os.ll_fpathconf",
-                      llimpl=fpathconf_llimpl)
-
-    @registering_if(os, 'pathconf')
-    def register_os_pathconf(self):
-        c_pathconf = self.llexternal('pathconf',
-                                     [rffi.CCHARP, rffi.INT], rffi.LONG)
-
-        def pathconf_llimpl(path, i):
-            rposix.set_errno(0)
-            res = c_pathconf(path, i)
-            if res == -1:
-                errno = rposix.get_errno()
-                if errno != 0:
-                    raise OSError(errno, "pathconf failed")
-            return res
-        return extdef([str0, int], int, "ll_os.ll_pathconf",
-                      llimpl=pathconf_llimpl)
-
-    @registering_if(os, 'confstr')
-    def register_os_confstr(self):
-        c_confstr = self.llexternal('confstr', [rffi.INT, rffi.CCHARP,
-                                                rffi.SIZE_T], rffi.SIZE_T)
-
-        def confstr_llimpl(i):
-            rposix.set_errno(0)
-            n = c_confstr(i, lltype.nullptr(rffi.CCHARP.TO), 0)
-            n = rffi.cast(lltype.Signed, n)
-            if n > 0:
-                buf = lltype.malloc(rffi.CCHARP.TO, n, flavor='raw')
-                try:
-                    c_confstr(i, buf, n)
-                    return rffi.charp2strn(buf, n)
-                finally:
-                    lltype.free(buf, flavor='raw')
-            else:
-                errno = rposix.get_errno()
-                if errno != 0:
-                    raise OSError(errno, "confstr failed")
-                return None
-        return extdef([int], SomeString(can_be_None=True),
-                      "ll_os.ll_confstr", llimpl=confstr_llimpl)
-
     @registering_if(os, 'getloadavg')
     def register_os_getloadavg(self):
         AP = rffi.CArrayPtr(lltype.Float)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to