[commit: packages/unix] master: Replace `__hsunix_getpw{nam, uid_r}` wrappers with CApiFFI (91b8238)

git at git.haskell.org git at git.haskell.org
Tue Apr 19 21:38:03 UTC 2016


Repository : ssh://git@git.haskell.org/unix

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/91b82383873b46385d239f2b059f353b11f07e0f/unix

>---------------------------------------------------------------

commit 91b82383873b46385d239f2b059f353b11f07e0f
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sun Jan 31 00:43:21 2016 +0100

    Replace `__hsunix_getpw{nam,uid_r}` wrappers with CApiFFI


>---------------------------------------------------------------

91b82383873b46385d239f2b059f353b11f07e0f
 System/Posix/User.hsc |  9 ++++++---
 cbits/HsUnix.c        | 18 ------------------
 include/HsUnix.h      | 12 ------------
 3 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc
index 01a417d..63bf466 100644
--- a/System/Posix/User.hsc
+++ b/System/Posix/User.hsc
@@ -53,7 +53,6 @@ import Foreign.C
 import Foreign.Ptr
 import Foreign.Marshal
 import Foreign.Storable
-import System.Posix.Internals   ( CGroup, CPasswd )
 
 #if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
 import Control.Concurrent.MVar  ( MVar, newMVar, withMVar )
@@ -64,6 +63,10 @@ import Control.Exception
 import Control.Monad
 import System.IO.Error
 
+-- internal types
+data {-# CTYPE "struct passwd" #-} CPasswd
+data {-# CTYPE "struct group"  #-} CGroup
+
 -- -----------------------------------------------------------------------------
 -- user environemnt
 
@@ -318,7 +321,7 @@ getUserEntryForID uid =
     doubleAllocWhileERANGE "getUserEntryForID" "user" pwBufSize unpackUserEntry $
       c_getpwuid_r uid ppw
 
-foreign import ccall unsafe "__hsunix_getpwuid_r"
+foreign import capi unsafe "HsUnix.h getpwuid_r"
   c_getpwuid_r :: CUid -> Ptr CPasswd ->
                         CString -> CSize -> Ptr (Ptr CPasswd) -> IO CInt
 #elif HAVE_GETPWUID
@@ -345,7 +348,7 @@ getUserEntryForName name =
       doubleAllocWhileERANGE "getUserEntryForName" "user" pwBufSize unpackUserEntry $
         c_getpwnam_r pstr ppw
 
-foreign import ccall unsafe "__hsunix_getpwnam_r"
+foreign import capi unsafe "HsUnix.h getpwnam_r"
   c_getpwnam_r :: CString -> Ptr CPasswd
                -> CString -> CSize -> Ptr (Ptr CPasswd) -> IO CInt
 #elif HAVE_GETPWNAM
diff --git a/cbits/HsUnix.c b/cbits/HsUnix.c
index aec5368..d689a6e 100644
--- a/cbits/HsUnix.c
+++ b/cbits/HsUnix.c
@@ -16,24 +16,6 @@ void *__hsunix_rtldNext (void) {return RTLD_NEXT;}
 void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;}
 #endif
 
-#if HAVE_GETPWNAM_R
-// getpwnam_r is a macro on some platforms, so we need a wrapper:
-int __hsunix_getpwnam_r(const char *name, struct passwd *pw, char *buffer,
-                        size_t buflen, struct passwd **result)
-{
-    return getpwnam_r(name, pw, buffer, buflen, result);
-}
-#endif
-
-#ifdef HAVE_GETPWUID_R
-// getpwuid_r is a macro on some platforms, so we need a wrapper:
-int __hsunix_getpwuid_r(uid_t uid, struct passwd *pw, char *buffer,
-                        size_t buflen, struct passwd **result)
-{
-    return getpwuid_r(uid, pw, buffer, buflen, result);
-}
-#endif
-
 #ifdef HAVE_PTSNAME
 // On Linux (and others), <stdlib.h> needs to be included while
 // `_XOPEN_SOURCE` is already defined. However, GHCs before GHC 8.0
diff --git a/include/HsUnix.h b/include/HsUnix.h
index 5daff0c..2f77d28 100644
--- a/include/HsUnix.h
+++ b/include/HsUnix.h
@@ -113,18 +113,6 @@ fall back to O_FSYNC, which should be the same */
 # define WCOREDUMP(s) 0
 #endif
 
-#if HAVE_GETPWNAM_R
-// getpwnam_r is a macro on some platforms, so we need a wrapper:
-int __hsunix_getpwnam_r(const char *, struct passwd *, char *, size_t,
-                        struct passwd **);
-#endif
-
-#ifdef HAVE_GETPWUID_R
-// getpwuid_r is a macro on some platforms, so we need a wrapper:
-int __hsunix_getpwuid_r(uid_t, struct passwd *, char *, size_t,
-                        struct passwd **);
-#endif
-
 #ifdef HAVE_PTSNAME
 char *__hsunix_ptsname(int fd);
 int __hsunix_grantpt(int fd);



More information about the ghc-commits mailing list