[commit: base] master: Convert some more declarations to use the CAPI (58a1bda)
Ian Lynagh
igloo at earth.li
Wed Feb 22 14:30:15 CET 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/base
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/58a1bda233c849bd94a6929465e4b69edad61448
>---------------------------------------------------------------
commit 58a1bda233c849bd94a6929465e4b69edad61448
Author: Ian Lynagh <igloo at earth.li>
Date: Tue Feb 21 18:33:22 2012 +0000
Convert some more declarations to use the CAPI
>---------------------------------------------------------------
System/Posix/Internals.hs | 12 ++++++------
System/Posix/Types.hs | 2 +-
include/CTypes.h | 6 ++++++
include/HsBase.h | 11 -----------
4 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/System/Posix/Internals.hs b/System/Posix/Internals.hs
index 7abded4..ae3477e 100644
--- a/System/Posix/Internals.hs
+++ b/System/Posix/Internals.hs
@@ -516,11 +516,11 @@ foreign import ccall unsafe "HsBase.h __hscore_o_noctty" o_NOCTTY :: CInt
foreign import ccall unsafe "HsBase.h __hscore_o_nonblock" o_NONBLOCK :: CInt
foreign import ccall unsafe "HsBase.h __hscore_o_binary" o_BINARY :: CInt
-foreign import ccall unsafe "HsBase.h __hscore_s_isreg" c_s_isreg :: CMode -> CInt
-foreign import ccall unsafe "HsBase.h __hscore_s_ischr" c_s_ischr :: CMode -> CInt
-foreign import ccall unsafe "HsBase.h __hscore_s_isblk" c_s_isblk :: CMode -> CInt
-foreign import ccall unsafe "HsBase.h __hscore_s_isdir" c_s_isdir :: CMode -> CInt
-foreign import ccall unsafe "HsBase.h __hscore_s_isfifo" c_s_isfifo :: CMode -> CInt
+foreign import capi unsafe "sys/stat.h S_ISREG" c_s_isreg :: CMode -> CInt
+foreign import capi unsafe "sys/stat.h S_ISCHR" c_s_ischr :: CMode -> CInt
+foreign import capi unsafe "sys/stat.h S_ISBLK" c_s_isblk :: CMode -> CInt
+foreign import capi unsafe "sys/stat.h S_ISDIR" c_s_isdir :: CMode -> CInt
+foreign import capi unsafe "sys/stat.h S_ISFIFO" c_s_isfifo :: CMode -> CInt
s_isreg :: CMode -> Bool
s_isreg cm = c_s_isreg cm /= 0
@@ -569,7 +569,7 @@ foreign import ccall unsafe "HsBase.h __hscore_ptr_c_cc" ptr_c_cc :: Ptr CTermi
s_issock :: CMode -> Bool
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
s_issock cmode = c_s_issock cmode /= 0
-foreign import ccall unsafe "HsBase.h __hscore_s_issock" c_s_issock :: CMode -> CInt
+foreign import ccall unsafe "sys/stat.h S_ISSOCK" c_s_issock :: CMode -> CInt
#else
s_issock _ = False
#endif
diff --git a/System/Posix/Types.hs b/System/Posix/Types.hs
index c599c84..0dc3beb 100644
--- a/System/Posix/Types.hs
+++ b/System/Posix/Types.hs
@@ -142,7 +142,7 @@ ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",HTYPE_DEV_T)
INTEGRAL_TYPE(CIno,tyConCIno,"CIno",HTYPE_INO_T)
#endif
#if defined(HTYPE_MODE_T)
-INTEGRAL_TYPE(CMode,tyConCMode,"CMode",HTYPE_MODE_T)
+INTEGRAL_TYPE_WITH_CTYPE(CMode,mode_t,tyConCMode,"CMode",HTYPE_MODE_T)
#endif
#if defined(HTYPE_OFF_T)
INTEGRAL_TYPE(COff,tyConCOff,"COff",HTYPE_OFF_T)
diff --git a/include/CTypes.h b/include/CTypes.h
index 1f7fae1..14ec79d 100644
--- a/include/CTypes.h
+++ b/include/CTypes.h
@@ -192,6 +192,12 @@ INSTANCE_READ(T,B); \
INSTANCE_SHOW(T,B); \
INSTANCE_TYPEABLE0(T,C,S) ;
+#define INTEGRAL_TYPE_WITH_CTYPE(T,THE_CTYPE,C,S,B) \
+newtype {-# CTYPE "THE_CTYPE" #-} T = T B deriving (ARITHMETIC_CLASSES, INTEGRAL_CLASSES); \
+INSTANCE_READ(T,B); \
+INSTANCE_SHOW(T,B); \
+INSTANCE_TYPEABLE0(T,C,S) ;
+
#define FLOATING_TYPE(T,C,S,B) \
newtype T = T B deriving (ARITHMETIC_CLASSES, FLOATING_CLASSES); \
INSTANCE_READ(T,B); \
diff --git a/include/HsBase.h b/include/HsBase.h
index bad3a4b..9b2e702 100644
--- a/include/HsBase.h
+++ b/include/HsBase.h
@@ -170,17 +170,6 @@ extern HsInt nocldstop;
INLINE int __hscore_get_errno(void) { return errno; }
INLINE void __hscore_set_errno(int e) { errno = e; }
-#if !defined(_MSC_VER)
-INLINE int __hscore_s_isreg(mode_t m) { return S_ISREG(m); }
-INLINE int __hscore_s_isdir(mode_t m) { return S_ISDIR(m); }
-INLINE int __hscore_s_isfifo(mode_t m) { return S_ISFIFO(m); }
-INLINE int __hscore_s_isblk(mode_t m) { return S_ISBLK(m); }
-INLINE int __hscore_s_ischr(mode_t m) { return S_ISCHR(m); }
-#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
-INLINE int __hscore_s_issock(mode_t m) { return S_ISSOCK(m); }
-#endif
-#endif
-
INLINE void *
__hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
{ return memcpy(dst, src+src_off, sz); }
More information about the Cvs-libraries
mailing list