From 6473a780bd38170c6813b70a735c5e282b10d24c Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Fri, 9 May 2008 14:53:34 +0000 Subject: [PATCH] Avoid calling varargs functions using the FFI 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 | 4 +++- Debug/Trace.hs | 4 +++- cbits/PrelIOUtils.c | 9 +++++++++ include/HsBase.h | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Control/Exception.hs b/Control/Exception.hs index 3fc1139..14bdef1 100644 --- a/Control/Exception.hs +++ b/Control/Exception.hs @@ -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 () diff --git a/Debug/Trace.hs b/Debug/Trace.hs index c30c811..742044e 100644 --- a/Debug/Trace.hs +++ b/Debug/Trace.hs @@ -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 diff --git a/cbits/PrelIOUtils.c b/cbits/PrelIOUtils.c index f37c4b6..556736e 100644 --- a/cbits/PrelIOUtils.c +++ b/cbits/PrelIOUtils.c @@ -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); +} diff --git a/include/HsBase.h b/include/HsBase.h index 8e5676a..f69e9cf 100644 --- a/include/HsBase.h +++ b/include/HsBase.h @@ -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__ */ -- 1.7.10.4