Permalink
Browse files

Merge branch 'bugfix/filehash-interrupts'

Fixes #55.
  • Loading branch information...
Sharpie committed Jan 27, 2012
2 parents 14f5137 + ff0d4c7 commit b0c08dcc4ae1c326f7c183b2b253bb9555402981
Showing with 31 additions and 5 deletions.
  1. +4 −5 R/cacheMetrics.R
  2. +12 −0 R/deviceUtils.R
  3. +3 −0 README.md
  4. +12 −0 src/tikzDevice.c
View
@@ -18,10 +18,11 @@ function( key )
checkDictionaryStatus()
# Check for the string.
- if ( dbExists(.tikzInternal[['dictionary']], sha1(key)) ) {
+ haveMetrics <- evalWithoutInterrupts(dbExists(.tikzInternal[['dictionary']], sha1(key)))
+ if ( haveMetrics ) {
# Yay! The width exists! Recover and return it.
- metrics <- dbFetch(.tikzInternal[['dictionary']], sha1(key))
+ metrics <- evalWithoutInterrupts(dbFetch(.tikzInternal[['dictionary']], sha1(key)))
} else {
@@ -41,12 +42,10 @@ function( key )
storeMetricsInDictionary <-
function( key, metrics )
{
-
- dbInsert(.tikzInternal[['dictionary']], sha1(key), metrics)
+ evalWithoutInterrupts(dbInsert(.tikzInternal[['dictionary']], sha1(key), metrics))
# Return nothing.
invisible()
-
}
View
@@ -187,6 +187,18 @@ getDeviceInfo <- function(dev_num = dev.cur()) {
return(device_info)
}
+# This function allows an R expression to be evaluated in a context where it
+# will be protected from user interrupts (use of CTRL-C for example).
+#
+#' @useDynLib tikzDevice TikZ_EvalWithoutInterrupts
+evalWithoutInterrupts <- function(expr, envir = parent.frame())
+{
+ # Wrap the expression in a call to `substitute` so that it gets passed
+ # directly to the C code instead of being evaluated before being passed to
+ # the C code.
+ .Call(TikZ_EvalWithoutInterrupts, substitute(expr), envir)
+}
+
#' Check If a String Contains Multibyte UTF-8 characters
#' This function is used by tikzDevice to check if an incoming string contains
View
@@ -136,6 +136,9 @@ Latest Changes
- Creating raster output with the tikzDevice could mess with the behavior of
some graphical paramaters such as par('mfrow'). This has been fixed.
+ - Calls to the Filehash package have been protected from user interruptions.
+ This should prevent rogue lockfiles and corrupted metrics dictionaries.
+
#### Behind the Scenes
- The tikzDevice now requires R 2.12.0 or later.
View
@@ -1857,6 +1857,18 @@ SEXP TikZ_DeviceInfo(SEXP device_num){
}
+/* Run R evaluations inside a context protected from things like CTRL-C */
+SEXP TikZ_EvalWithoutInterrupts(SEXP expr, SEXP envir){
+ SEXP result;
+
+ BEGIN_SUSPEND_INTERRUPTS{
+ result = eval(expr, envir);
+ }END_SUSPEND_INTERRUPTS;
+
+ return result;
+}
+
+
/*==============================================================================
Utility Routines

0 comments on commit b0c08dc

Please sign in to comment.