From ae84d1fc7b3cb0f4ab70e4b4879707213c2286ba Mon Sep 17 00:00:00 2001 From: Judah Jacobson <judah.jacobson@gmail.com> Date: Sat, 28 Apr 2012 23:05:54 +0000 Subject: [PATCH] Workaround for Cabal ticket #944. This patch is a modified version of one submitted by Paul van der Walt. It adds a "haskeline_" prefix to all of Haskeline's C symbol names. This avoids clashing symbol names with other packages that implement the same C functions. (In particular, it prevents a clash with vty on "mk_wcswidth".) --- System/Console/Haskeline/Backend/IConv.hsc | 6 +++--- System/Console/Haskeline/Backend/WCWidth.hs | 4 ++-- System/Console/Haskeline/Backend/Win32.hsc | 2 +- cbits/h_iconv.c | 6 +++--- cbits/h_wcwidth.c | 20 ++++++++++---------- cbits/win_console.c | 2 +- includes/h_iconv.h | 6 +++--- includes/win_console.h | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/System/Console/Haskeline/Backend/IConv.hsc b/System/Console/Haskeline/Backend/IConv.hsc index f972606..b6f3585 100644 --- a/System/Console/Haskeline/Backend/IConv.hsc +++ b/System/Console/Haskeline/Backend/IConv.hsc @@ -87,7 +87,7 @@ getCodeset = do type IConvT = ForeignPtr () type IConvTPtr = Ptr () -foreign import ccall "h_iconv_open" iconv_open +foreign import ccall "haskeline_iconv_open" iconv_open :: CString -> CString -> IO IConvTPtr iconvOpen :: String -> String -> IO IConvT @@ -101,9 +101,9 @@ iconvOpen destName srcName = withCAString destName $ \dest -> else newForeignPtr iconv_close res -- really this returns a CInt, but it's easiest to just ignore that, I think. -foreign import ccall "& h_iconv_close" iconv_close :: FunPtr (IConvTPtr -> IO ()) +foreign import ccall "& haskeline_iconv_close" iconv_close :: FunPtr (IConvTPtr -> IO ()) -foreign import ccall "h_iconv" c_iconv :: IConvTPtr -> Ptr CString -> Ptr CSize +foreign import ccall "haskeline_iconv" c_iconv :: IConvTPtr -> Ptr CString -> Ptr CSize -> Ptr CString -> Ptr CSize -> IO CSize data Result = Successful diff --git a/System/Console/Haskeline/Backend/WCWidth.hs b/System/Console/Haskeline/Backend/WCWidth.hs index f06a165..be7ae3f 100644 --- a/System/Console/Haskeline/Backend/WCWidth.hs +++ b/System/Console/Haskeline/Backend/WCWidth.hs @@ -13,10 +13,10 @@ import System.Console.Haskeline.LineState import Data.List import Foreign.C.Types -foreign import ccall unsafe mk_wcwidth :: CWchar -> CInt +foreign import ccall unsafe haskeline_mk_wcwidth :: CWchar -> CInt wcwidth :: Char -> Int -wcwidth c = case mk_wcwidth $ toEnum $ fromEnum c of +wcwidth c = case haskeline_mk_wcwidth $ toEnum $ fromEnum c of -1 -> 0 -- Control characters have zero width. (Used by the -- "\SOH...\STX" hack in LineState.stringToGraphemes.) w -> fromIntegral w diff --git a/System/Console/Haskeline/Backend/Win32.hsc b/System/Console/Haskeline/Backend/Win32.hsc index 4f6ae98..36d6f85 100644 --- a/System/Console/Haskeline/Backend/Win32.hsc +++ b/System/Console/Haskeline/Backend/Win32.hsc @@ -171,7 +171,7 @@ instance Storable Coord where (#poke COORD, Y) p (toEnum (coordY c) :: CShort) -foreign import ccall "SetPosition" +foreign import ccall "haskeline_SetPosition" c_SetPosition :: HANDLE -> Ptr Coord -> IO Bool setPosition :: HANDLE -> Coord -> IO () diff --git a/cbits/h_iconv.c b/cbits/h_iconv.c index 71234c8..7f8e17a 100644 --- a/cbits/h_iconv.c +++ b/cbits/h_iconv.c @@ -1,15 +1,15 @@ #include "h_iconv.h" // Wrapper functions, since iconv_open et al are macros in libiconv. -iconv_t h_iconv_open(const char *tocode, const char *fromcode) { +iconv_t haskeline_iconv_open(const char *tocode, const char *fromcode) { return iconv_open(tocode, fromcode); } -void h_iconv_close(iconv_t cd) { +void haskeline_iconv_close(iconv_t cd) { iconv_close(cd); } -size_t h_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, +size_t haskeline_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { // Cast inbuf to (void*) so that it works both on Solaris, which expects // a (const char**), and on other platforms (e.g. Linux), which expect diff --git a/cbits/h_wcwidth.c b/cbits/h_wcwidth.c index 61e822a..b4ca548 100644 --- a/cbits/h_wcwidth.c +++ b/cbits/h_wcwidth.c @@ -67,7 +67,7 @@ struct interval { }; /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) { +static int haskeline_bisearch(wchar_t ucs, const struct interval *table, int max) { int min = 0; int mid; @@ -119,7 +119,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) { * in ISO 10646. */ -int mk_wcwidth(wchar_t ucs) +int haskeline_mk_wcwidth(wchar_t ucs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ @@ -181,7 +181,7 @@ int mk_wcwidth(wchar_t ucs) return -1; /* binary search in table of non-spacing characters */ - if (bisearch(ucs, combining, + if (haskeline_bisearch(ucs, combining, sizeof(combining) / sizeof(struct interval) - 1)) return 0; @@ -204,12 +204,12 @@ int mk_wcwidth(wchar_t ucs) } -int mk_wcswidth(const wchar_t *pwcs, size_t n) +int haskeline_mk_wcswidth(const wchar_t *pwcs, size_t n) { int w, width = 0; for (;*pwcs && n-- > 0; pwcs++) - if ((w = mk_wcwidth(*pwcs)) < 0) + if ((w = haskeline_mk_wcwidth(*pwcs)) < 0) return -1; else width += w; @@ -227,7 +227,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n) * the traditional terminal character-width behaviour. It is not * otherwise recommended for general use. */ -int mk_wcwidth_cjk(wchar_t ucs) +int haskeline_mk_wcwidth_cjk(wchar_t ucs) { /* sorted list of non-overlapping intervals of East Asian Ambiguous * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ @@ -287,20 +287,20 @@ int mk_wcwidth_cjk(wchar_t ucs) }; /* binary search in table of non-spacing characters */ - if (bisearch(ucs, ambiguous, + if (haskeline_bisearch(ucs, ambiguous, sizeof(ambiguous) / sizeof(struct interval) - 1)) return 2; - return mk_wcwidth(ucs); + return haskeline_mk_wcwidth(ucs); } -int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) +int haskeline_mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) { int w, width = 0; for (;*pwcs && n-- > 0; pwcs++) - if ((w = mk_wcwidth_cjk(*pwcs)) < 0) + if ((w = haskeline_mk_wcwidth_cjk(*pwcs)) < 0) return -1; else width += w; diff --git a/cbits/win_console.c b/cbits/win_console.c index 74df387..c8ae01a 100644 --- a/cbits/win_console.c +++ b/cbits/win_console.c @@ -1,5 +1,5 @@ #include "win_console.h" -BOOL SetPosition(HANDLE h, COORD* c) { +BOOL haskeline_SetPosition(HANDLE h, COORD* c) { return SetConsoleCursorPosition(h,*c); } diff --git a/includes/h_iconv.h b/includes/h_iconv.h index 9022381..b4a88c3 100644 --- a/includes/h_iconv.h +++ b/includes/h_iconv.h @@ -1,9 +1,9 @@ #include <iconv.h> -iconv_t h_iconv_open(const char *tocode, const char *fromcode); +iconv_t haskeline_iconv_open(const char *tocode, const char *fromcode); -void h_iconv_close(iconv_t cd); +void haskeline_iconv_close(iconv_t cd); -size_t h_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, +size_t haskeline_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); diff --git a/includes/win_console.h b/includes/win_console.h index bccd3b7..cfe24a2 100644 --- a/includes/win_console.h +++ b/includes/win_console.h @@ -2,6 +2,6 @@ #define _WIN_CONSOLE_H #include <windows.h> -BOOL SetPosition(HANDLE h, COORD* c); +BOOL haskeline_SetPosition(HANDLE h, COORD* c); #endif -- GitLab