[Fencommits] fenserve: unload modules every time, to prevent using the first successfully loaded version over and over again (the code is pretty stupid)

Benja Fallenstein benja.fallenstein at gmail.com
Fri Mar 23 05:41:40 EET 2007


Fri Mar 23 05:41:30 EET 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * unload modules every time, to prevent using the first successfully loaded version over and over again (the code is pretty stupid)
diff -rN -u old-fenserve/FenServe.hs new-fenserve/FenServe.hs
--- old-fenserve/FenServe.hs	2007-03-23 05:41:39.000000000 +0200
+++ new-fenserve/FenServe.hs	2007-03-23 05:41:39.000000000 +0200
@@ -267,14 +267,14 @@
 execute :: Node -> Request -> FenServe Result
 execute code req = do
     s <- getBlock (bID code)
-    let errH stage msg = return $ \req -> return $
+    let errH stage msg = return $ (,) Nothing $ \req -> return $ 
             mkResult 500 "text/plain" $ toUTF $ stage ++ " failed:\n" ++ msg
         s2 = "module Page_" ++ (blockId $ bID code) ++ " where\n" ++
                      "dummyAssignment = 0\n" ++ fromUTF s
                      -- the 'dummyAssignment' is to make sure that
                      -- pages can't import anything -- imports are
                      -- syntactically disallowed except at the beginning
-    h <- case Hsx.parseModuleWithMode (Hsx.ParseMode "Page.hs") $ s2 of
+    (m,h) <- case Hsx.parseModuleWithMode (Hsx.ParseMode "Page.hs") $ s2 of
         ParseFailed (SrcLoc file line col) err -> errH "HSP preprocessing" $ 
             "At "++show line++":"++show col++" in "++file++": "++err
         ParseOk parsed -> return $ unsafePerformIO $ do
@@ -295,11 +295,14 @@
                Plugins.MakeSuccess _ o -> do
                    loadResult <- Plugins.load o [dir] [homedir ++ "/.ghc/i386-linux-6.6/package.conf"] "handler"
                    case loadResult of
-                       Plugins.LoadSuccess _ v -> return v
+                       Plugins.LoadSuccess m v -> return (Just m,v)
                        Plugins.LoadFailure err ->
                            errH "Load" $ concat (List.intersperse "\n" err)
            removeFile fp; return h'
-    h req -- run the loaded handler
+    result <- h req -- run the loaded handler
+    case m of Just m' -> unsafePerformIO $ do Plugins.unload m'
+                                              return (return result)
+              Nothing -> return result
 
 
 -------------------------------------------------------------------------




More information about the Fencommits mailing list