(Hugs only) conform to the current FFI spec. This code makes the
additional assumption that a finalizer added with addForeignPtrFinalizer
runs before any existing finalizers on the same object.
-> Int -- ^ Flags (summed together)
-> IO Regex -- ^ Returns: the compiled regular expression
regcomp pattern flags = do
-> Int -- ^ Flags (summed together)
-> IO Regex -- ^ Returns: the compiled regular expression
regcomp pattern flags = do
+#ifdef __HUGS__
+ regex_fptr <- mallocForeignPtrBytes (#const sizeof(regex_t))
+#else
regex_ptr <- mallocBytes (#const sizeof(regex_t))
regex_fptr <- newForeignPtr regex_ptr (regfree regex_ptr)
regex_ptr <- mallocBytes (#const sizeof(regex_t))
regex_fptr <- newForeignPtr regex_ptr (regfree regex_ptr)
r <- withCString pattern $ \cstr ->
withForeignPtr regex_fptr $ \p ->
c_regcomp p cstr (fromIntegral flags)
r <- withCString pattern $ \cstr ->
withForeignPtr regex_fptr $ \p ->
c_regcomp p cstr (fromIntegral flags)
+#ifdef __HUGS__
+ addForeignPtrFinalizer regex_fptr ptr_regfree
+#endif
if (r == 0)
then return (Regex regex_fptr)
else error "Text.Regex.Posix.regcomp: error in pattern" -- ToDo
if (r == 0)
then return (Regex regex_fptr)
else error "Text.Regex.Posix.regcomp: error in pattern" -- ToDo
regfree :: Ptr CRegex -> IO ()
regfree p_regex = do
c_regfree p_regex
free p_regex
regfree :: Ptr CRegex -> IO ()
regfree p_regex = do
c_regfree p_regex
free p_regex
-- -----------------------------------------------------------------------------
-- regexec
-- -----------------------------------------------------------------------------
-- regexec
-- Flags for regexec
#enum Int,, \
REG_NOTBOL, \
-- Flags for regexec
#enum Int,, \
REG_NOTBOL, \
-- Return values from regexec
#enum Int,, \
-- Return values from regexec
#enum Int,, \
foreign import ccall unsafe "regcomp"
c_regcomp :: Ptr CRegex -> CString -> CInt -> IO CInt
foreign import ccall unsafe "regcomp"
c_regcomp :: Ptr CRegex -> CString -> CInt -> IO CInt
+#ifdef __HUGS__
+foreign import ccall unsafe "®free"
+ ptr_regfree :: FunPtr (Ptr CRegex -> IO ())
+#else
foreign import ccall unsafe "regfree"
c_regfree :: Ptr CRegex -> IO ()
foreign import ccall unsafe "regfree"
c_regfree :: Ptr CRegex -> IO ()
foreign import ccall unsafe "regexec"
c_regexec :: Ptr CRegex -> CString -> CSize
foreign import ccall unsafe "regexec"
c_regexec :: Ptr CRegex -> CString -> CSize