Skip to content

Commit 709114d

Browse files
author
Jeremy Shaw
committed
some minor haddock improvements and removal of trailing whitespace
1 parent 682a2dc commit 709114d

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

src/System/Plugins/Load.hs

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
{-# LANGUAGE UnboxedTuples #-}
44
{-# LANGUAGE ForeignFunctionInterface #-}
55
--
6-
-- Copyright (C) 2004-5 Don Stewart - http://www.cse.unsw.edu.au/~dons
7-
--
6+
-- Copyright (C) 2004-5 Don Stewart
7+
--
88
-- This library is free software; you can redistribute it and/or
99
-- modify it under the terms of the GNU Lesser General Public
1010
-- License as published by the Free Software Foundation; either
1111
-- version 2.1 of the License, or (at your option) any later version.
12-
--
12+
--
1313
-- This library is distributed in the hope that it will be useful,
1414
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1616
-- Lesser General Public License for more details.
17-
--
17+
--
1818
-- You should have received a copy of the GNU Lesser General Public
1919
-- License along with this library; if not, write to the Free Software
2020
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
2121
-- USA
22-
--
22+
--
2323

2424
-- | An interface to the GHC runtime's dynamic linker, providing runtime
2525
-- loading and linking of Haskell object files, commonly known as
@@ -34,7 +34,7 @@ module System.Plugins.Load (
3434
, load
3535
, load_
3636
, dynload
37-
, pdynload
37+
, pdynload
3838
, pdynload_
3939
, unload
4040
, unloadAll
@@ -149,7 +149,7 @@ data LoadStatus a
149149
-- provided with appropriate type constraints such that Haskell compiler
150150
-- can determine the expected type returned by 'load', as the return
151151
-- type is notionally polymorphic.
152-
--
152+
--
153153
-- Example:
154154
--
155155
-- > do mv <- load "Plugin.o" ["api"] [] "resource"
@@ -184,18 +184,21 @@ load obj incpaths pkgconfs sym = do
184184
#endif
185185
addModuleDeps m' moduleDeps
186186
v <- loadFunction m sym
187-
return $ case v of
187+
return $ case v of
188188
Nothing -> LoadFailure ["load: couldn't find symbol <<"++sym++">>"]
189189
Just a -> LoadSuccess m a
190190

191191
--
192192
-- | Like load, but doesn't want a package.conf arg (they are rarely used)
193193
--
194-
load_ :: FilePath -> [FilePath] -> Symbol -> IO (LoadStatus a)
194+
load_ :: FilePath -- ^ object file
195+
-> [FilePath] -- ^ any include paths
196+
-> Symbol -- ^ symbol to find
197+
-> IO (LoadStatus a)
195198
load_ o i s = load o i [] s
196199

197-
--
198-
-- A work-around for Dynamics. The keys used to compare two TypeReps are
200+
201+
-- | A work-around for Dynamics. The keys used to compare two TypeReps are
199202
-- somehow not equal for the same type in hs-plugin's loaded objects.
200203
-- Solution: implement our own dynamics...
201204
--
@@ -204,8 +207,8 @@ load_ o i s = load o i [] s
204207
-- is not the case, we core dump. Use pdynload if you don't trust the
205208
-- user to supply you with a Dynamic
206209
--
207-
dynload :: Typeable a
208-
=> FilePath
210+
dynload :: Typeable a
211+
=> FilePath
209212
-> [FilePath]
210213
-> [PackageConf]
211214
-> Symbol
@@ -220,7 +223,8 @@ dynload obj incpaths pkgconfs sym = do
220223
Nothing -> LoadFailure ["Mismatched types in interface"]
221224

222225
------------------------------------------------------------------------
223-
--
226+
227+
-- |
224228
-- The super-replacement for dynload
225229
--
226230
-- Use GHC at runtime so we get staged type inference, providing full
@@ -229,23 +233,22 @@ dynload obj incpaths pkgconfs sym = do
229233
--
230234
-- TODO where does the .hc file go in the call to build() ?
231235
--
232-
233236
pdynload :: FilePath -- ^ object to load
234237
-> [FilePath] -- ^ include paths
235238
-> [PackageConf] -- ^ package confs
236239
-> Type -- ^ API type
237240
-> Symbol -- ^ symbol
238241
-> IO (LoadStatus a)
239242

240-
pdynload object incpaths pkgconfs ty sym = do
243+
pdynload object incpaths pkgconfs ty sym = do
241244
#if DEBUG
242245
putStr "Checking types ... " >> hFlush stdout
243246
#endif
244247
errors <- unify object incpaths [] ty sym
245248
#if DEBUG
246249
putStrLn "done"
247250
#endif
248-
if null errors
251+
if null errors
249252
then load object incpaths pkgconfs sym
250253
else return $ LoadFailure errors
251254

@@ -269,12 +272,12 @@ pdynload_ object incpaths pkgconfs args ty sym = do
269272
#if DEBUG
270273
putStrLn "done"
271274
#endif
272-
if null errors
275+
if null errors
273276
then load object incpaths pkgconfs sym
274277
else return $ LoadFailure errors
275278

276279
------------------------------------------------------------------------
277-
-- run the typechecker over the constraint file
280+
-- | run the typechecker over the constraint file
278281
--
279282
-- Problem: if the user depends on a non-auto package to build the
280283
-- module, then that package will not be in scope when we try to build
@@ -290,7 +293,7 @@ unify obj incs args ty sym = do
290293
(tmpf1,hdl1) <- mkTemp -- and send .hi file here.
291294
hClose hdl1
292295

293-
let nm = mkModid (basename tmpf)
296+
let nm = mkModid (basename tmpf)
294297
src = mkTest nm (hierize' . mkModid . hierize $ obj)
295298
(fst $ break (=='.') ty) ty sym
296299
is = map ("-i"++) incs -- api
@@ -312,7 +315,7 @@ unify obj incs args ty sym = do
312315
hierize' ('\\':cs) = '.' : hierize' cs
313316
hierize' (c:cs) = c : hierize' cs
314317

315-
mkTest modnm plugin api ty sym =
318+
mkTest modnm plugin api ty sym =
316319
"module "++ modnm ++" where" ++
317320
"\nimport qualified " ++ plugin ++
318321
"\nimport qualified " ++ api ++
@@ -327,11 +330,11 @@ mkTest modnm plugin api ty sym =
327330
pdynload obj incpaths pkgconfs sym ty = do
328331
(m, v) <- load obj incpaths pkgconfs sym
329332
ty' <- mungeIface sym obj
330-
if ty == ty'
333+
if ty == ty'
331334
then return $ Just (m, v)
332335
else return Nothing -- mismatched types
333336
334-
where
337+
where
335338
-- grab the iface output from GHC. find the line relevant to our
336339
-- symbol. grab the string rep of the type.
337340
mungeIface sym o = do
@@ -348,11 +351,11 @@ pdynload obj incpaths pkgconfs sym ty = do
348351
--
349352
-- a version of load the also unwraps and types a Dynamic object
350353
--
351-
dynload2 :: Typeable a =>
352-
FilePath ->
353-
FilePath ->
354+
dynload2 :: Typeable a =>
355+
FilePath ->
356+
FilePath ->
354357
Maybe [PackageConf] ->
355-
Symbol ->
358+
Symbol ->
356359
IO (Module, a)
357360
358361
dynload2 obj incpath pkgconfs sym = do
@@ -402,13 +405,13 @@ reload m@(Module{path = p, iface = hi}) sym = do
402405
#endif
403406
m_ <- loadObject p . Object . ifaceModuleName $ hi -- load object at path p
404407
let m' = m_ { iface = hi }
405-
408+
406409
resolveObjs (unloadAll m)
407410
#if DEBUG
408411
putStrLn "done" >> hFlush stdout
409412
#endif
410413
v <- loadFunction m' sym
411-
return $ case v of
414+
return $ case v of
412415
Nothing -> LoadFailure ["load: couldn't find symbol <<"++sym++">>"]
413416
Just a -> LoadSuccess m' a
414417

@@ -493,31 +496,29 @@ loadPackageFunction pkgName modName functionName =
493496
-- NB the environment stores the *full path* to an object. So if you
494497
-- want to know if a module is already loaded, you need to supply the
495498
-- *path* to that object, not the name.
496-
--
499+
--
497500
-- NB -- let's try just the module name.
498501
--
499502
-- loadObject loads normal .o objs, and packages too. .o objs come with
500503
-- a nice canonical Z-encoded modid. packages just have a simple name.
501504
-- Do we want to ensure they won't clash? Probably.
502505
--
503-
506+
--
504507
--
505508
-- the second argument to loadObject is a string to use as the unique
506509
-- identifier for this object. For normal .o objects, it should be the
507510
-- Z-encoded modid from the .hi file. For archives\/packages, we can
508511
-- probably get away with the package name
509512
--
510-
511-
512513
loadObject :: FilePath -> Key -> IO Module
513-
loadObject p ky@(Object k) = loadObject' p ky k
514-
loadObject p ky@(Package k) = loadObject' p ky k
514+
loadObject p ky@(Object k) = loadObject' p ky k
515+
loadObject p ky@(Package k) = loadObject' p ky k
515516

516517
loadObject' :: FilePath -> Key -> String -> IO Module
517518
loadObject' p ky k
518519
| ("HSrts"++sysPkgSuffix) `isSuffixOf` p = return (emptyMod p)
519520

520-
| otherwise
521+
| otherwise
521522
= do alreadyLoaded <- isLoaded k
522523
when (not alreadyLoaded) $ do
523524
r <- withCString p c_loadObj
@@ -527,7 +528,7 @@ loadObject' p ky k
527528

528529
where emptyMod q = Module q (mkModid q) Vanilla undefined ky
529530

530-
--
531+
-- |
531532
-- load a single object. no dependencies. You should know what you're
532533
-- doing.
533534
--
@@ -560,11 +561,11 @@ resolveObjs unloadLoaded
560561

561562

562563
-- | Unload a module
563-
unloadObj :: Module -> IO ()
564+
unloadObj :: Module -> IO ()
564565
unloadObj (Module { path = p, kind = k, key = ky }) = case k of
565566
Vanilla -> withCString p $ \c_p -> do
566567
removed <- rmModule name
567-
when (removed) $ do r <- c_unloadObj c_p
568+
when (removed) $ do r <- c_unloadObj c_p
568569
when (not r) (panic "unloadObj: failed")
569570
Shared -> return () -- can't unload .so?
570571
where name = case ky of Object s -> s ; Package pk -> pk
@@ -579,14 +580,14 @@ loadShared str = do
579580
putStrLn $ " shared: " ++ str
580581
#endif
581582
maybe_errmsg <- withCString str $ \dll -> c_addDLL dll
582-
if maybe_errmsg == nullPtr
583+
if maybe_errmsg == nullPtr
583584
then return (Module str (mkModid str) Shared undefined (Package (mkModid str)))
584585
else do e <- peekCString maybe_errmsg
585586
panic $ "loadShared: couldn't load `"++str++"\' because "++e
586587

587588

588589
--
589-
-- Load a -package that we might need, implicitly loading the cbits too
590+
-- | Load a -package that we might need, implicitly loading the cbits too
590591
-- The argument is the name of package (e.g. \"concurrent\")
591592
--
592593
-- How to find a package is determined by the package.conf info we store
@@ -610,7 +611,7 @@ loadPackage p = do
610611

611612

612613
--
613-
-- Unload a -package, that has already been loaded. Unload the cbits
614+
-- | Unload a -package, that has already been loaded. Unload the cbits
614615
-- too. The argument is the name of the package.
615616
--
616617
-- May need to check if it exists.
@@ -625,12 +626,12 @@ unloadPackage pkg = do
625626
let pkg' = takeWhile (/= '-') pkg -- in case of *-0.1
626627
libs <- liftM (\(a,_) -> (filter (isSublistOf pkg') ) a) (lookupPkg pkg)
627628
flip mapM_ libs $ \p -> withCString p $ \c_p -> do
628-
r <- c_unloadObj c_p
629+
r <- c_unloadObj c_p
629630
when (not r) (panic "unloadObj: failed")
630-
rmModule (mkModid p) -- unrecord this module
631+
rmModule (mkModid p) -- unrecord this module
631632

632633
--
633-
-- load a package using the given package.conf to help
634+
-- | load a package using the given package.conf to help
634635
-- TODO should report if it doesn't actually load the package, instead
635636
-- of mapM_ doing nothing like above.
636637
--
@@ -644,10 +645,10 @@ loadPackageWith p pkgconfs = do
644645
#if DEBUG
645646
putStrLn " done"
646647
#endif
647-
648+
648649

649650
-- ---------------------------------------------------------------------
650-
-- module dependency loading
651+
-- | module dependency loading
651652
--
652653
-- given an Foo.o vanilla object file, supposed to be a plugin compiled
653654
-- by our library, find the associated .hi file. If this is found, load
@@ -684,11 +685,11 @@ loadDepends obj incpaths = do
684685

685686
-- now, try to generate a path to the actual .o file
686687
-- fix up hierachical names
687-
let mods_ = map (\s -> (s, map (\c ->
688+
let mods_ = map (\s -> (s, map (\c ->
688689
if c == '.' then '/' else c) $ s)) ds'
689690

690691
-- construct a list of possible dependent modules to load
691-
let mods = concatMap (\p ->
692+
let mods = concatMap (\p ->
692693
map (\(hi,m) -> (hi,p </> m++".o")) mods_) incpaths
693694

694695
-- remove modules that don't exist
@@ -717,15 +718,15 @@ loadDepends obj incpaths = do
717718
#endif
718719
resolveObjs (mapM_ unloadPackage ps')
719720
#if DEBUG
720-
when (not (null ps')) $ putStrLn "done"
721-
putStr "Loading object"
721+
when (not (null ps')) $ putStrLn "done"
722+
putStr "Loading object"
722723
mapM_ (\(m,_) -> putStr (" "++ m) >> hFlush stdout) mods''
723724
#endif
724725
moduleDeps <- mapM (\(hi,m) -> loadObject m (Object hi)) mods''
725726
return (hiface,moduleDeps)
726727

727728
-- ---------------------------------------------------------------------
728-
-- Nice interface to .hi parser
729+
-- | Nice interface to .hi parser
729730
--
730731
getImports :: String -> IO [String]
731732
getImports m = do

0 commit comments

Comments
 (0)