~alcinnz/fontconfig-pure

f8fdd180c8ce9f95507dc16873186743e5bc6d03 — Adrian Cochrane 7 months ago 583a886
Attempted segfault fix.
M Graphics/Text/Font/Choose/CharSet.hs => Graphics/Text/Font/Choose/CharSet.hs +6 -5
@@ 8,7 8,8 @@ import Data.Word (Word32)
import Foreign.Ptr
import Control.Exception (bracket)
import Control.Monad (forM)
import Foreign.Marshal.Alloc (alloca, allocaBytes)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Array (allocaArray)
import GHC.Base (unsafeChr)
import Data.Char (ord, isHexDigit)
import Numeric (readHex)


@@ 61,10 62,10 @@ foreign import ccall "FcCharSetAddChar" fcCharSetAddChar :: CharSet_ -> Word32 -
thawCharSet :: CharSet_ -> IO CharSet
thawCharSet chars'
    | chars' == nullPtr = return Set.empty
    | otherwise = allocaBytes fcCHARSET_MAP_SIZE $ \iter' -> alloca $ \next' -> do
    | otherwise = allocaArray fcCHARSET_MAP_SIZE $ \iter' -> alloca $ \next' -> do
        first <- fcCharSetFirstPage chars' iter' next'
        let go = do
                ch <- fcCharSetNextPage chars' iter' next';
                ch <- fcCharSetNextPage chars' iter' next'
                if ch == maxBound then return []
                else do
                    chs <- go


@@ 72,9 73,9 @@ thawCharSet chars'
        if first == maxBound then return Set.empty else do
            rest <- go
            return $ Set.fromList $ map (unsafeChr . fromIntegral) (first:rest)
foreign import ccall "FcCharSetFirstPage" fcCharSetFirstPage ::
foreign import ccall "my_FcCharSetFirstPage" fcCharSetFirstPage ::
    CharSet_ -> Ptr Word32 -> Ptr Word32 -> IO Word32
foreign import ccall "FcCharSetNextPage" fcCharSetNextPage ::
foreign import ccall "my_FcCharSetNextPage" fcCharSetNextPage ::
    CharSet_ -> Ptr Word32 -> Ptr Word32 -> IO Word32
foreign import ccall "my_FcCHARSET_MAP_SIZE" fcCHARSET_MAP_SIZE :: Int


M Graphics/Text/Font/Choose/FontSet.hs => Graphics/Text/Font/Choose/FontSet.hs +0 -2
@@ 55,8 55,6 @@ withFontSets' (fonts:fontss) i fontss' cb = withFontSet fonts $ \fonts' -> do

thawFontSet :: FontSet_ -> IO FontSet
thawFontSet fonts' = do
    -- Very hacky, but these debug statements must be in here to avoid segfaults.
    -- FIXME: Is there an alternative?
    n <- get_fontSet_nfont fonts'
    if n == 0 then return []
    else

M cbits/pattern.c => cbits/pattern.c +8 -1
@@ 2,7 2,14 @@
#include <stddef.h>

int my_FcCHARSET_MAP_SIZE() {
    return FC_CHARSET_MAP_SIZE*sizeof(FcChar32);
    return FC_CHARSET_MAP_SIZE;
}

FcChar32 my_FcCharSetFirstPage(const FcCharSet *a, FcChar32 *map, FcChar32 *next) {
    return FcCharSetFirstPage(a, map, next);
}
FcChar32 my_FcCharSetNextPage(const FcCharSet *a, FcChar32 *map, FcChar32 *next) {
    return FcCharSetNextPage(a, map, next);
}

FcBool my_FcPatternAdd(FcPattern *p, const char *object,

M fontconfig-pure.cabal => fontconfig-pure.cabal +1 -1
@@ 10,7 10,7 @@ name:                fontconfig-pure
-- PVP summary:      +-+------- breaking API changes
--                   | | +----- non-breaking API additions
--                   | | | +--- code changes with no API change
version:             0.1.1.1
version:             0.2.0.0

-- A short (one-line) description of the package.
synopsis:            Pure-functional language bindings to FontConfig