nanovg 0.8.0.0 → 0.8.1.0
raw patch · 4 files changed
+35/−11 lines, 4 filesdep ~bytestringdep ~textdep ~vector
Dependency ranges changed: bytestring, text, vector
Files
- CHANGELOG.md +10/−0
- nanovg.cabal +2/−2
- src/NanoVG/Internal/FFIHelpers.hs +19/−5
- src/NanoVG/Internal/Text.chs +4/−4
CHANGELOG.md view
@@ -1,3 +1,13 @@+0.8.1.0+-------++* Fix use after free in `createFontMem` #17++0.8.0.0+-------++* Windows support+ 0.6.0.0 ---
nanovg.cabal view
@@ -1,5 +1,5 @@ name: nanovg-version: 0.8.0.0+version: 0.8.1.0 synopsis: Haskell bindings for nanovg description: Raw bindings to the OpenGL vector graphics library NanoVG homepage: https://github.com/cocreature/nanovg-hs@@ -70,7 +70,7 @@ exposed-modules: NanoVG.Internal.GL3 build-depends: base >= 4.8 && <5.0- , bytestring >= 0.10 && < 0.11+ , bytestring >= 0.10 && < 0.12 , containers >= 0.5 && < 0.7 , text >= 1.2 && < 1.3 , vector >= 0.11 && < 0.13
src/NanoVG/Internal/FFIHelpers.hs view
@@ -2,11 +2,12 @@ (withCString ,useAsCStringLen' ,useAsPtr- ,zero+ ,one ,null ,bitMask ) where +import Control.Monad ((>=>)) import Data.Bits ((.|.)) import Data.ByteString hiding (null) import qualified Data.Set as S@@ -14,6 +15,7 @@ import qualified Data.Text.Encoding as T import Foreign.C.String (CString) import Foreign.C.Types+import Foreign.Marshal (copyBytes, mallocBytes) import Foreign.Ptr import Prelude hiding (null) @@ -23,15 +25,27 @@ -- | Wrapper around 'useAsCStringLen' that uses 'CUChar's useAsCStringLen' :: ByteString -> ((Ptr CUChar,CInt) -> IO a) -> IO a-useAsCStringLen' bs f = useAsCStringLen bs (\(ptr,len) -> f (castPtr ptr,fromIntegral len))+useAsCStringLen' bs f = useAsCStringLen bs ((\(ptr,len) -> return (castPtr ptr,fromIntegral len)) >=> copyCStringLen >=> f)+ where+ -- | Copy memory under given pointer to a new address.+ -- The allocated memory is not garbage-collected and needs to be freed manually later.+ -- In the case of 'createFontMem' and 'createFontMemAtIndex' (the only places using it)+ -- it is freed by NanoVG as a part of 'nvgDeleteGL3'.+ copyCStringLen :: Integral b => (Ptr a, b) -> IO (Ptr a, b)+ copyCStringLen (from, len) =+ let intLen = fromIntegral len+ in do+ to <- mallocBytes intLen+ copyBytes to from intLen+ return (to, len) -- | Wrapper around 'useAsCStringLen'' that discards the length useAsPtr :: ByteString -> (Ptr CUChar -> IO a) -> IO a useAsPtr bs f = useAsCStringLen' bs (f . fst) --- | Marshalling helper for a constant zero-zero :: Num a => (a -> b) -> b-zero f = f 0+-- | Marshalling helper for a constant one+one :: Num a => (a -> b) -> b+one f = f 1 -- | Marshalling helper for a constant 'nullPtr' null :: (Ptr a -> b) -> b
src/NanoVG/Internal/Text.chs view
@@ -105,16 +105,16 @@ {#fun unsafe nvgCreateFontAtIndex as createFontAtIndex {`Context',withCString*`T.Text','withCString.unwrapFileName'*`FileName', `CInt'} -> `Maybe Font'safeFont#} --- | Creates image by loading it from the specified memory chunk.+-- | Creates font by loading it from the specified memory chunk. -- Returns handle to the font. {#fun unsafe nvgCreateFontMem as createFontMem- {`Context',withCString*`T.Text',useAsCStringLen'*`ByteString'&,zero-`CInt'} -> `Maybe Font'safeFont#}+ {`Context',withCString*`T.Text',useAsCStringLen'*`ByteString'&,one-`CInt'} -> `Maybe Font'safeFont#} --- | Creates image by loading it from the specified memory chunk.+-- | Creates font by loading it from the specified memory chunk. -- fontIndex specifies which font face to load from a .ttf/.ttc file. -- Returns handle to the font. {#fun unsafe nvgCreateFontMemAtIndex as createFontMemAtIndex- {`Context',withCString*`T.Text',useAsCStringLen'*`ByteString'&,zero-`CInt',`CInt'} -> `Maybe Font'safeFont#}+ {`Context',withCString*`T.Text',useAsCStringLen'*`ByteString'&,one-`CInt',`CInt'} -> `Maybe Font'safeFont#} -- | Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found. {#fun unsafe nvgFindFont as findFont