[darcs-devel] darcs patch: atexit

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue Jan 25 00:54:27 PST 2005


Hello!

Here's the atexit implementation for darcs.

The actions are called in reverse order of their registration. Exceptions
thrown by actions are caught and reported, but remaining actions are still
performed. Actions can't register new actions, any such event is reported -
this is to prevent looping.

This should really go into a comment... I promise I will add it.

I'm not sure I placed with_atexit in the right place with respect to other
wrappers.

Best regards,
Tomasz
-------------- next part --------------

New patches:

[add AtExit.lhs
Tomasz Zielonka <tomasz.zielonka at gmail.com>**20050125075257] {
addfile ./AtExit.lhs
hunk ./AtExit.lhs 1
+\begin{code}
+
+module AtExit ( atexit,
+                with_atexit 
+              ) where
+
+import Control.Concurrent.MVar
+import Control.Exception (bracket_, catch, block, unblock)
+import System.IO.Unsafe (unsafePerformIO)
+import System.IO (hPutStrLn, stderr)
+import Prelude hiding (catch)
+
+{-# NOINLINE atexit_actions #-}
+atexit_actions :: MVar (Maybe [IO ()])
+atexit_actions = unsafePerformIO (newMVar (Just []))
+
+atexit :: IO () -> IO ()
+atexit action = do
+    modifyMVar_ atexit_actions $ \ml -> do
+        case ml of
+            Just l -> do
+                return (Just (action : l))
+            Nothing -> do
+                hPutStrLn stderr "It's too late to use atexit"
+                return Nothing
+
+with_atexit :: IO a -> IO a
+with_atexit prog = do
+    bracket_
+        (return ())
+        exit
+        prog
+  where
+    exit = block $ do
+        Just actions <- swapMVar atexit_actions Nothing
+        -- from now on atexit will not register new actions
+        mapM_ runAction actions
+    runAction action = do
+        catch (unblock action) $ \exn -> do
+            hPutStrLn stderr $ "Exception thrown by an atexit registered action:"
+            hPutStrLn stderr $ show exn
+
+\end{code}
}

[wrap main in with_atexit
Tomasz Zielonka <tomasz.zielonka at gmail.com>**20050125084411] {
hunk ./GNUmakefile 29
-	Workaround.hs Zlib.lhs FileSystem.hs
+	Workaround.hs Zlib.lhs FileSystem.hs AtExit.lhs
hunk ./darcs.lhs 45
+import AtExit ( with_atexit )
hunk ./darcs.lhs 592
-main = withSignalsHandled $ handleJust assertions bug $ do
+main = with_atexit $ withSignalsHandled $ handleJust assertions bug $ do
}

Context:

[fixed bug in get --partial not applying patches
andrew at siaris.net**20050124100341] 
[Slurp again in Get, but only if slurping is cheap.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20050124005142] 
[Implement maybe_slurp_recorded.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20050124005128] 
[Don't slurp twice when getting.
Juliusz Chroboczek <jch at pps.jussieu.fr>*-20050121185241] 
[speed up whatsnew -l just a tad.
David Roundy <droundy at abridgegame.org>**20050123221105] 
[Limit the number of lines printed on fetch failure.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20050120202139] 
[fix bug in push.pl test.
David Roundy <droundy at abridgegame.org>**20050123144629] 
[filter out conflict markers in prefs/ files.
David Roundy <droundy at abridgegame.org>**20050123143514] 
[fix bug in tests/pull.pl, which formerly caused no trouble.
David Roundy <droundy at abridgegame.org>**20050123143438] 
[give better error messages when unable to access a repository.
David Roundy <droundy at abridgegame.org>**20050123141034
 Well, at least give *more* error messages...
] 
[add failing test case for changes after a directory rename.
David Roundy <droundy at abridgegame.org>**20050123133557] 
[fix bug in changes when directory has been moved.
David Roundy <droundy at abridgegame.org>**20050123131245] 
[remove test for error message that has been removed.
David Roundy <droundy at abridgegame.org>**20050123124402] 
[add configurable character encoding to cgi
Will <will at glozer.net>**20050122210109] 
[use "impossible" to report error cases that should never occur.
David Roundy <droundy at abridgegame.org>**20050122154355] 
[Fix non-modular access to current (breaks current.none).
Juliusz Chroboczek <jch at pps.jussieu.fr>**20050121203134
 Touching _darcs/current outside of Current cannot be done now; this
 directory might not exist.
] 
[Don't slurp twice when getting.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20050121185241] 
[Documentation fix: not everyone is working on darcs itself.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20050121183827] 
[fix bug in get --partial when checkpointed tag is preceded by patch not in tag.
David Roundy <droundy at abridgegame.org>**20050121131948
 This fix would be more thorough if I made optimize reorder the patches so
 that this didn't happen.  However, that's potentially a slow and dangerous
 optimization, so I'm leaving it for future implementation.
] 
[add test for partial repos
Tommy Pettersson <ptp at lysator.liu.se>**20050117003129] 
[update the ChangeLog.
David Roundy <droundy at abridgegame.org>**20050120134351] 
[added 'darcs 1.0.1' to User-Agent when using HTTP
ketil at ii.uib.no**20050115103050] 
[Added request to include --exact-version info in bug report
marnix.klooster at ssaglobal.com**20050117053621] 
[document trackdown a bit more
Tommy Pettersson <ptp at lysator.liu.se>**20050117010501] 
[add --patches etc flags to changes.
David Roundy <droundy at abridgegame.org>**20050115141425] 
[clarify --ask-deps docs
Mark Stosberg <mark at summersault.com>**20050114152216
 
 This moves a paragraph about dependencies below the --ask-deps option, which
 clarifies which direction the dependencies work.
] 
[make --ask-deps a multiple-choice option
Tommy Pettersson <ptp at lysator.liu.se>**20050114162455] 
[Add "Thumbs.db" to default boring prefs.
Matt Brubeck <mbrubeck at cs.hmc.edu>**20050114161252
 Thumbs.db is a system file generated by Windows Explorer, when viewing a
 folder that contains image files.
] 
[Added linux kernel boring stuff to default boring list
Kirill Smelkov <kirr at landau.phys.spbu.ru>**20050114104331
 
 I added
 .o.cmd
 .ko
 .ko.cmd
 .mod.c
 .tmp_versions
] 
[Avoid #ifdefs for posix imports
peter at zarquon.se**20050111150419] 
[do not unconditionally append darcs to etc
Jim Radford <radford at blackbean.org>**20050111191748
 The makefile takes care of appending darcs to the etc directory when
 needed so do not do it (again) unconditionally in configure.ac.
 
] 
[Allow ncurses in addition to curses
sreindl at triobit.de**20050110052431] 
[clean up check_a_patch.
David Roundy <droundy at abridgegame.org>**20050110134842] 
[clean up merge_three_patches test script.
David Roundy <droundy at abridgegame.org>**20050109141321] 
[eliminate deprecated read_repo_patches, which was only used once.
David Roundy <droundy at abridgegame.org>**20050109131532] 
[add a little more documentation for --match, --patch and --tag
Mark Stosberg <mark at summersault.com>**20050108175143] 
[move doc chunk to make docs easier to read in the code.
Mark Stosberg <mark at summersault.com>**20050108174424] 
[fix bug in merger commutation and add test case illustrating problem.
David Roundy <droundy at abridgegame.org>**20050108153759] 
[Lessen the scare factor in 'darcs send' which said: 'Sending by email to'
zander at kde.org**20050108135028
 after which it started asking for user-permission, while the initial message
 gave the impression it would not.
 Now it says: 'Found email to send to a at b.com'
] 
[update darcs-users mailing list address to @darcs.net
Tommy Pettersson <ptp at lysator.liu.se>**20050107000618] 
[further improve optimize docs based on feedback from David R
Mark Stosberg <mark at summersault.com>**20050106231247] 
[clarify RSS feed is of stable repo
Mark Stosberg <mark at summersault.com>**20050106144547] 
[flesh out patch options docs for annotate in more detail. 
Mark Stosberg <mark at summersault.com>**20050102222711] 
[improve docs for --partial, --checkpoint and optimize
Mark Stosberg <mark at summersault.com>**20050106040024
 
 I moved the documentation for --partial and --checkpoint from the "common
 options" section into few commands that actually use them.
 
 I also tried to add details about what exactly these do and when to use them.
 
 Special thanks to Juliusz Chroboczek for his input here.
 
 Notice that I need left one 'TODO' in the patch that seemed worth fixing, and
 easy enough to do soon.
 
     Mark
 
] 
[Use isHexDigit, not isDigit, when looking for =nn QP characters
Ian Lynagh <igloo at earth.li>**20050104233209] 
[s/~/ /
Mark Stosberg <mark at summersault.com>**20050104182645] 
[be clearer that '--unified' is usually darcs-specific.
Mark Stosberg <mark at summersault.com>**20050102223336] 
[fix posix imports for win32 builds
Will <will at glozer.net>**20050104004332] 
[do not use `-e' as a short form of --set-scripts-executable option
Karel Gardas <kgardas at objectsecurity.com>**20050102190722] 
[enhance `pull' command to support --set/dont-set-scripts-executable options
Karel Gardas <kgardas at objectsecurity.com>**20050101223751] 
[enhance `apply' command to support --set/dont-set-scripts-executable options
Karel Gardas <kgardas at objectsecurity.com>**20050101223645] 
[fix syntax errors in my last doc patch that prevented darcs from compiling.
Mark Stosberg <mark at summersault.com>**20050101192840] 
[clarify annotate docs
Mark Stosberg <mark at summersault.com>**20041231153708
 
 I think a primary reason that annotate has been confusing is because it is
 documented as provided 'useful information'. This is too vague to be useful
 information. :)
 
 So I tried to figure out exactly what annotate does do, and be explicit
 in the documentation about that.
 
 I was a little surprised that annotate didn't have a line number option.
 It seems it already has the ability to report when a specific line was last changed. 
 
 If this were to be implemented, it would be nice to support relative and absolute line ranges,
 so you could express: "Report on lines within 10 lines from here".
] 
[replace `if' with `when' to improve readability in my recent slurp changes
Karel Gardas <kgardas at objectsecurity.com>**20041230222254] 
[remove some GHC 6.0.3 compatibility #ifdefs
Karel Gardas <kgardas at objectsecurity.com>**20041230203913] 
[make darcs changes --context support --to-patch, etc
Anthony Towns <aj at azure.humbug.org.au>**20041222203754] 
[rename 'unix script to 'script' in Karel's patch
Mark Stosberg <mark at summersault.com>**20041229224115] 
[enhance `get' command to support --set/donot-set-unix-scripts-executable options
Karel Gardas <kgardas at objectsecurity.com>**20041228222948] 
[enhance slurp write related and repository apply_patches functions to support executable scripts
Karel Gardas <kgardas at objectsecurity.com>**20041228212713
 This patch enhances slurp write related functions and repository
 apply_patches function to make Unix scripts executable if appropriate
 -e/--set-unix-scripts-executable option is used.
] 
[add --set-unix-scripts-executable and --donot-set-unix-scripts-executable options support
Karel Gardas <kgardas at objectsecurity.com>**20041228123330] 
[add FileSystem module with basic implementation of make_executable function
Karel Gardas <kgardas at objectsecurity.com>**20041228114555
 This patch adds FileSystem module which is intended to provide various
 file system related functions and hide under-laying OS
 functionality. Currently only `make_executable' function is provided
 which makes file executable for its owner and owner group on
 Unix(-like) OSes and does nothing on Win32 OSes.
] 
[revert nice error message on patch parsing.
David Roundy <droundy at abridgegame.org>**20041229153258
 The problem was that darcs tries parsing patch bundles different ways to
 see whether it's been mime-encoded or not, and failing with errorDoc rather
 than by returning Nothing breaks that.  If we want nicer messages for parse
 errors, we should switch from Maybe (Patch, PackedString) to Either Doc
 (Patch, PackedString).
] 
[add configure option to fix path to sendmail even if it's not present.
David Roundy <droundy at abridgegame.org>**20041229151244] 
[Add RSS feed of latest repo changes to darcs.net homepage.
Mark Stosberg <mark at summersault.com>**20041229004651
 
 A temporary preview of this is here:
 http://mark.stosberg.com/Tech/darcs/front.html
 
 David suggested it would be desirable to also have the author's
 named displayed. That appears to be possible because that information 
 is in the feed in an <author> tag. However, I don't have the patience
 to make that work tonight. If someone else wants to, feel free.
 
] 
[bash completion made more robust regarding shell special chars
Guillaume Outters <guillaume.outters at free.fr>**20041228231448
 IFS set to CR, for correct spliting of darcs --list-option entries containing spaces.
 We escape all special characters using printf %q, so that the shell passes us our parameters back as we want them.
] 
[avoid duplicated code in commute and commute_no_merger.
David Roundy <droundy at abridgegame.org>**20041222142807] 
[Reorganize breakup of Patch to avoid circular dependencies.
David Roundy <droundy at abridgegame.org>**20041221141512] 
[resolve conflict with whitespace change.
David Roundy <droundy at abridgegame.org>**20041221130035] 
[Rejig patch headings so documentation makes some sense again
Ian Lynagh <igloo at earth.li>**20041217174449] 
[Merge changes
Ian Lynagh <igloo at earth.li>**20041217165950] 
[Split Patch up more. Unfortunately needs a .hi-boot file.
Ian Lynagh <igloo at earth.li>**20041211024030] 
[disallow accidently pushing to the current repo
Mark Stosberg <mark at summersault.com>**20041219172359] 
[Test for pulling from current repo before setting it as the default
Mark Stosberg <mark at summersault.com>**20041219171533] 
[Some more tests for push. 
Mark Stosberg <mark at summersault.com>**20041219163241] 
[provide better stripCr implementation
Will <will at glozer.net>**20041219031418] 
[add konquerer workaround to cgi annotate
Will <will at glozer.net>**20041219024435] 
[use fail when possible for errors.
David Roundy <droundy at abridgegame.org>**20041218153234] 
[address #114 - provide a better error when you accidently try to pull from yourself
Mark Stosberg <mark at summersault.com>**20041218025451
 
 This was my first real experiment with Haskell, so someone who knows better
 will probably want to rewrite it. :) 
 
 Also, this only addresses the 'pull' case. It may be better put this logic in a
 shared routine, so it be used by 'push' and elsewhere.  
] 
[remove trailing whitespace
simons at cryp.to**20041218004144] 
[don't import type 'Patch' twice
simons at cryp.to**20041218004106] 
[remove duplicate imports (error in ghc-6.3)
simons at cryp.to**20041218002402] 
[avoid conflicts by importing only 'bug' from DarcsUtils
simons at cryp.to**20041218002301] 
[Fix manual to state 'darcs get' has --tag, not --tag-name
zander at kde.org**20041217153547] 
[strip trailing CR in pref files
Will <will at glozer.net>**20041216073907] 
[fix typo in mingw reference
Lode Leroy <lode_leroy at hotmail.com>**20041202131840] 
[fix bug that left junk equal to identity patch in pending.
David Roundy <droundy at abridgegame.org>**20041215134337] 
[typo fix
Mark Stosberg <mark at summersault.com>**20041215023027] 
[removing Amending patches from basic documentation
Mark Stosberg <mark at summersault.com>**20041106030942
 
 I really like this clear description of what Amend record is actually doing.
 I've submitted a patch to the stable repo to merge some of the wording here
 into the (currently sparse) docs for admend-record.
 
 Amend-record is a more advanced, dangerous command which doesn't belong in a
 "Basics" section, so I removed it here.
] 
[improve documentation clarity
Mark Stosberg <mark at summersault.com>**20041106030733] 
[improve formatting of 'working' and 'current'
Mark Stosberg <mark at summersault.com>**20041106030657] 
[documentation, basics on creating patches
Tommy Pettersson <ptp at lysator.liu.se>**20041103111151] 
[update webpage to say 1.0.1 is latest stable source now.
David Roundy <droundy at abridgegame.org>**20041214134854] 
[TAG 1.0.1
David Roundy <droundy at abridgegame.org>**20041214131758] 
Patch bundle hash:
63047f74383d879716b04d038410efa03d7bacfa


More information about the darcs-devel mailing list