[jruby-joni] 158/279: Make the regexp engine respect via Thread.interrupt().

Hideki Yamane henrich at moszumanska.debian.org
Mon Nov 16 11:27:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit 1822b0f30e0e85071183f1e7a082f5476a437294
Author: Jordan Sissel <jls at semicomplete.com>
Date:   Tue Apr 2 10:22:37 2013 -0700

    Make the regexp engine respect via Thread.interrupt().
    
    The use case is that some regexp executions can take exponential time.
    A documented case and explanation is found here:
      http://swtch.com/~rsc/regexp/regexp1.html
    
    In cases where exponential runtime is undesirable, it would be nice if
    we could interrupt the engine. To do this, running the pattern in a
    separate thread and then interrupting that thread when it doesn't
    complete on schule.
---
 src/org/joni/ByteCodeMachine.java | 7 +++++--
 src/org/joni/Matcher.java         | 8 ++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index 9056166..a9e0e08 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -169,7 +169,7 @@ class ByteCodeMachine extends StackMachine {
         }
     }
 
-    protected final int matchAt(int range, int sstart, int sprev) {
+    protected final int matchAt(int range, int sstart, int sprev) throws InterruptedException {
         this.range = range;
         this.sstart = sstart;
         this.sprev = sprev;
@@ -186,6 +186,9 @@ class ByteCodeMachine extends StackMachine {
 
         final int[]code = this.code;
         while (true) {
+            if (Thread.interrupted()) {
+                throw new InterruptedException();
+            }
             if (Config.DEBUG_MATCH) debugMatchLoop();
 
             sbegin = s;
@@ -1744,4 +1747,4 @@ class ByteCodeMachine extends StackMachine {
     private int finish() {
         return bestLen;
     }
-}
\ No newline at end of file
+}
diff --git a/src/org/joni/Matcher.java b/src/org/joni/Matcher.java
index 4fa923d..ebca342 100644
--- a/src/org/joni/Matcher.java
+++ b/src/org/joni/Matcher.java
@@ -59,7 +59,7 @@ public abstract class Matcher extends IntHolder {
     }
 
     // main matching method
-    protected abstract int matchAt(int range, int sstart, int sprev);
+    protected abstract int matchAt(int range, int sstart, int sprev) throws InterruptedException;
 
     protected abstract void stateCheckBuffInit(int strLength, int offset, int stateNum);
     protected abstract void stateCheckBuffClear();
@@ -86,7 +86,7 @@ public abstract class Matcher extends IntHolder {
         if (Config.USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE) msaBestLen = -1;
     }
 
-    public final int match(int at, int range, int option) {
+    public final int match(int at, int range, int option) throws InterruptedException {
         msaInit(option, at);
 
         if (Config.USE_COMBINATION_EXPLOSION_CHECK) {
@@ -277,7 +277,7 @@ public abstract class Matcher extends IntHolder {
     }
 
     // MATCH_AND_RETURN_CHECK
-    private boolean matchCheck(int upperRange, int s, int prev) {
+    private boolean matchCheck(int upperRange, int s, int prev) throws InterruptedException {
         if (Config.USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE) {
             if (Config.USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE) {
                 //range = upperRange;
@@ -302,7 +302,7 @@ public abstract class Matcher extends IntHolder {
         return false;
     }
 
-    public final int search(int start, int range, int option) {
+    public final int search(int start, int range, int option) throws InterruptedException {
         int s, prev;
         int origStart = start;
         int origRange = range;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list