[tor-dev] PRELIMINARY: [PATCH 3/3] Replace 'TorDNSEL.System.Timeout' with 'System.Timeout'.

Nikita Karetnikov nikita at karetnikov.org
Mon Jul 22 05:16:21 UTC 2013


I apologize for the delay.  Here are three patches.

The first one deals with this issue: "GHC was recently changed to not
allow you to use newtypes in FFI imports unless the constructor of the
newtype is in scope." [1]

The second patch removes a redundant function and adjusts some imports.
(I wrote a version of 'splitByDelimiter' that uses 'B.breakSubstring'
instead of 'B.findSubstrings'.  Let me know if you want to keep
'splitByDelimiter', and I'll use that version.)

The third patch removes 'TorDNSEL.System.Timeout'.  There is a similar
module in 'base' (see [2], for instance).  In TorDNSEL, this line

  (bracket (forkIO (threadDelay n >> throwDynTo pid ex))

wraps a 'Timeout' exception into 'Dynamic' [3] and raises the exception
after 'n' microseconds.  And this one

  handleJust (\e -> dynExceptions e >>= fromDynamic >>= guard . (ex ==))

catches dynamic exceptions and compares them with the 'Timeout'
exception.  I think there is no need to use dynamic exceptions at all.

The latest version of 'System.Timeout' [4] is also similar but uses
'forkIOWithUnmask' [5].  It seems safer because it doesn't rely on
'MaskingState' [6] of a parent thread (also, see [7]).

There is another reason to remove 'TorDNSEL.System.Timeout': it's the
only module that is not in the public domain.

If you apply the attached patches on top of the previous patchset [8],
you should see some exception-related errors, which I haven't fixed yet.
(Don't forget that the mentioned patches are preliminary and need
additional testing.)

[1] http://ghc.haskell.org/trac/ghc/ticket/5610
[2] http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/src/System-Timeout.html
[3] http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Control-OldException.html#v%3AthrowDynTo
[4] http://hackage.haskell.org/packages/archive/base/4.6.0.1/doc/html/src/System-Timeout.html#timeout
[5] http://hackage.haskell.org/packages/archive/base/4.6.0.1/doc/html/src/GHC-Conc-Sync.html#forkIOWithUnmask
[6] http://hackage.haskell.org/packages/archive/base/4.6.0.1/doc/html/src/GHC-IO.html#MaskingState
[7] http://ofps.oreilly.com/titles/9781449335946/sec_cancellation.html
[8] https://lists.torproject.org/pipermail/tor-dev/2013-July/005134.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Do-not-use-GHC.IOBase-and-B.findSubstrings.patch
Type: text/x-diff
Size: 2335 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130722/8435531d/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Import-the-CInt-constructor-properly.patch
Type: text/x-diff
Size: 728 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130722/8435531d/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Replace-TorDNSEL.System.Timeout-with-System.Timeout.patch
Type: text/x-diff
Size: 8927 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130722/8435531d/attachment-0002.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130722/8435531d/attachment.sig>


More information about the tor-dev mailing list