diff --git a/NgxExport/Tools/PCRE.hs b/NgxExport/Tools/PCRE.hs index d4c9533..4c5f673 100644 --- a/NgxExport/Tools/PCRE.hs +++ b/NgxExport/Tools/PCRE.hs @@ -1,7 +1,4 @@ {-# LANGUAGE TemplateHaskell, BangPatterns, OverloadedStrings #-} -{-# LANGUAGE ForeignFunctionInterface, CApiFFI #-} - -{-# OPTIONS_GHC -fno-warn-dodgy-foreign-imports #-} ----------------------------------------------------------------------------- -- | @@ -43,16 +40,10 @@ import qualified Data.ByteString.Lazy as L import Data.List import Data.Maybe import Data.IORef -import Text.Regex.PCRE.Light hiding (compile, compileM) -import Text.Regex.PCRE.Light.Base -import Text.Regex.PCRE.Heavy hiding (compileM) +import Text.Regex.PCRE.Light +import Text.Regex.PCRE.Heavy import Control.Exception (Exception, throwIO) import Control.Arrow -import Foreign.Ptr -import Foreign.ForeignPtr -import Foreign.C.String -import Foreign.Storable -import Foreign.Marshal.Alloc import System.IO.Unsafe -- $matchingPCRE @@ -173,34 +164,6 @@ declareRegexes = ignitionService $ const $ return "" ngxExportSimpleServiceTyped 'declareRegexes ''InputRegexes SingleShotService - -{- SPLICE: compile with pcre_free finalizer, mostly adopted from pcre-light -} - -foreign import capi "pcre.h value pcre_free" c_pcre_free' :: FinalizerPtr a - -compile :: ByteString -> [PCREOption] -> Regex -compile s o = case compileM s o of - Right r -> r - Left e -> error ("Text.Regex.PCRE.Light: Error in regex: " ++ e) - -compileM :: ByteString -> [PCREOption] -> Either String Regex -compileM str os = unsafePerformIO $ - C8.useAsCString str $ \ptn -> - alloca $ \errptr -> - alloca $ \erroffset -> do - pcre_ptr <- c_pcre_compile ptn (combineOptions os) - errptr erroffset nullPtr - if pcre_ptr == nullPtr - then do - err <- peekCString =<< peek errptr - return (Left err) - else do - reg <- newForeignPtr c_pcre_free' pcre_ptr - return (Right (Regex reg str)) - -{- SPLICE: END -} - - compileRegexes :: ByteString -> IO L.ByteString compileRegexes = const $ do !inputRegexes <- fromJust <$> readIORef storage_InputRegexes_declareRegexes diff --git a/ngx-export-tools-extra.cabal b/ngx-export-tools-extra.cabal index a20a87c..bfc9dc3 100644 --- a/ngx-export-tools-extra.cabal +++ b/ngx-export-tools-extra.cabal @@ -78,7 +78,7 @@ library , aeson >= 1.0.0.0 && < 2.0.0.0 if flag(PCRE) - build-depends: pcre-light >= 0.4 + build-depends: pcre-light >= 0.4.1.2 , pcre-heavy exposed-modules: NgxExport.Tools.Aggregate