Avoid calling varargs functions using the FFI
authorSimon Marlow <marlowsd@gmail.com>
Fri, 9 May 2008 14:53:34 +0000 (14:53 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 9 May 2008 14:53:34 +0000 (14:53 +0000)
Calling varargs functions is explicitly deprecated according to the
FFI specification.  It used to work, just about, but it broke with the
recent changes to the via-C backend to not use header files.

Control/Exception.hs
Debug/Trace.hs
cbits/PrelIOUtils.c
include/HsBase.h

index 3fc1139..14bdef1 100644 (file)
@@ -581,7 +581,9 @@ uncaughtExceptionHandler = unsafePerformIO (newIORef defaultHandler)
           withCString msg $ \cmsg ->
             errorBelch cfmt cmsg
 
-foreign import ccall unsafe "RtsMessages.h errorBelch"
+-- don't use errorBelch() directly, because we cannot call varargs functions
+-- using the FFI.
+foreign import ccall unsafe "HsBase.h errorBelch2"
    errorBelch :: CString -> CString -> IO ()
 
 setUncaughtExceptionHandler :: (Exception -> IO ()) -> IO ()
index c30c811..742044e 100644 (file)
@@ -41,7 +41,9 @@ putTraceMsg msg = do
      withCString msg  $ \cmsg ->
       debugBelch cfmt cmsg
 
-foreign import ccall unsafe "RtsMessages.h debugBelch"
+-- don't use debugBelch() directly, because we cannot call varargs functions
+-- using the FFI.
+foreign import ccall unsafe "HsBase.h debugBelch2"
    debugBelch :: CString -> CString -> IO ()
 #endif
 
index f37c4b6..556736e 100644 (file)
@@ -7,3 +7,12 @@
 #define INLINE
 #include "HsBase.h"
 
+void errorBelch2(const char*s, char *t)
+{
+    return errorBelch(s,t);
+}
+
+void debugBelch2(const char*s, char *t)
+{
+    return debugBelch(s,t);
+}
index 8e5676a..f69e9cf 100644 (file)
@@ -732,5 +732,8 @@ INLINE void *    __hscore_from_intptr (intptr_t n)  { return (void *)n; }
 INLINE uintptr_t __hscore_to_uintptr  (void *p)     { return (uintptr_t)p; }
 INLINE intptr_t  __hscore_to_intptr   (void *p)     { return (intptr_t)p; }
 
+void errorBelch2(const char*s, char *t);
+void debugBelch2(const char*s, char *t);
+
 #endif /* __HSBASE_H__ */