[jruby-joni] 09/31: fix for Onigmo #43

Hideki Yamane henrich at moszumanska.debian.org
Sat Feb 24 10:44:58 UTC 2018


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 a779d3564c797157ed9ef4bdccb66ee79034e39f
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date:   Thu Feb 1 18:08:42 2018 +0100

    fix for Onigmo #43
---
 src/org/joni/Analyser.java        | 12 ++++++++--
 src/org/joni/ArrayCompiler.java   | 46 ++++++++++++++++++++++++---------------
 src/org/joni/ByteCodeMachine.java |  2 +-
 test/org/joni/test/TestU8.java    |  4 ++++
 4 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index 467fc46..ce83cc2 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -1789,6 +1789,8 @@ final class Analyser extends Parser {
     private static final int IN_NOT                     = (1<<1);
     private static final int IN_REPEAT                  = (1<<2);
     private static final int IN_VAR_REPEAT              = (1<<3);
+    private static final int IN_CALL                    = (1<<4);
+    private static final int IN_RECCALL                 = (1<<5);
     private static final int EXPAND_STRING_MAX_LENGTH   = 100;
 
     /* setup_tree does the following work.
@@ -1931,11 +1933,17 @@ final class Analyser extends Parser {
                 break;
 
             case EncloseType.MEMORY:
-                if ((state & (IN_ALT | IN_NOT | IN_VAR_REPEAT)) != 0) {
+                if ((state & (IN_ALT | IN_NOT | IN_VAR_REPEAT | IN_CALL)) != 0) {
                     env.btMemStart = bsOnAt(env.btMemStart, en.regNum);
                     /* SET_ENCLOSE_STATUS(node, NST_MEM_IN_ALT_NOT); */
-
                 }
+                if (en.isCalled()) state |= IN_CALL;
+                if (en.isRecursion()) {
+                    state |= IN_RECCALL;
+                } else if ((state & IN_RECCALL) != 0){
+                    en.setRecursion();
+                }
+
                 setupTree(en.target, state);
                 break;
 
diff --git a/src/org/joni/ArrayCompiler.java b/src/org/joni/ArrayCompiler.java
index ce1a326..736d68c 100644
--- a/src/org/joni/ArrayCompiler.java
+++ b/src/org/joni/ArrayCompiler.java
@@ -843,8 +843,15 @@ final class ArrayCompiler extends Compiler {
                 } else {
                     len += node.isRecursion() ? OPSize.MEMORY_END_REC : OPSize.MEMORY_END;
                 }
-            } else { // USE_SUBEXP_CALL
+            } else if (Config.USE_SUBEXP_CALL && node.isRecursion()) { // USE_SUBEXP_CALL
                 len = OPSize.MEMORY_START_PUSH; // or OPSize.MEMORY_START;
+                len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH_REC : OPSize.MEMORY_END_REC);
+            } else {
+                if (bsAt(regex.btMemStart, node.regNum)) {
+                    len = OPSize.MEMORY_START_PUSH;
+                } else {
+                    len= OPSize.MEMORY_START;
+                }
                 len += tlen + (bsAt(regex.btMemEnd, node.regNum) ? OPSize.MEMORY_END_PUSH : OPSize.MEMORY_END);
             }
             break;
@@ -889,22 +896,20 @@ final class ArrayCompiler extends Compiler {
         int len;
         switch (node.type) {
         case EncloseType.MEMORY:
-            if (Config.USE_SUBEXP_CALL) {
-                if (node.isCalled()) {
-                    regex.requireStack = true;
-                    addOpcode(OPCode.CALL);
-                    node.callAddr = codeLength + OPSize.ABSADDR + OPSize.JUMP;
-                    node.setAddrFixed();
-                    addAbsAddr(node.callAddr);
-                    len = compileLengthTree(node.target);
-                    len += OPSize.MEMORY_START_PUSH + OPSize.RETURN;
-                    if (bsAt(regex.btMemEnd, node.regNum)) {
-                        len += node.isRecursion() ? OPSize.MEMORY_END_PUSH_REC : OPSize.MEMORY_END_PUSH;
-                    } else {
-                        len += node.isRecursion() ? OPSize.MEMORY_END_REC : OPSize.MEMORY_END;
-                    }
-                    addOpcodeRelAddr(OPCode.JUMP, len);
+            if (Config.USE_SUBEXP_CALL && node.isCalled()) {
+                regex.requireStack = true;
+                addOpcode(OPCode.CALL);
+                node.callAddr = codeLength + OPSize.ABSADDR + OPSize.JUMP;
+                node.setAddrFixed();
+                addAbsAddr(node.callAddr);
+                len = compileLengthTree(node.target);
+                len += OPSize.MEMORY_START_PUSH + OPSize.RETURN;
+                if (bsAt(regex.btMemEnd, node.regNum)) {
+                    len += node.isRecursion() ? OPSize.MEMORY_END_PUSH_REC : OPSize.MEMORY_END_PUSH;
+                } else {
+                    len += node.isRecursion() ? OPSize.MEMORY_END_REC : OPSize.MEMORY_END;
                 }
+                addOpcodeRelAddr(OPCode.JUMP, len);
             } // USE_SUBEXP_CALL
 
             if (bsAt(regex.btMemStart, node.regNum)) {
@@ -925,7 +930,14 @@ final class ArrayCompiler extends Compiler {
                 }
                 addMemNum(node.regNum);
                 addOpcode(OPCode.RETURN);
-            } else { // USE_SUBEXP_CALL
+            } else if (Config.USE_SUBEXP_CALL && node.isRecursion()) { // USE_SUBEXP_CALL
+                if (bsAt(regex.btMemEnd, node.regNum)) {
+                    addOpcode(OPCode.MEMORY_END_PUSH_REC);
+                } else {
+                    addOpcode(OPCode.MEMORY_END_REC);
+                }
+                addMemNum(node.regNum);
+            } else {
                 if (bsAt(regex.btMemEnd, node.regNum)) {
                     addOpcode(OPCode.MEMORY_END_PUSH);
                 } else {
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index 0d01bee..85d9916 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -488,7 +488,7 @@ class ByteCodeMachine extends StackMachine {
                     if (me != INVALID_INDEX) {
                         int ms = repeatStk[memStartStk + i];
                         region.beg[i] = (bsAt(regex.btMemStart, i) ? stack[ms].getMemPStr() : ms) - str;
-                        region.end[i] = bsAt(regex.btMemEnd, i) ? stack[me].getMemPStr() : me - str;
+                        region.end[i] = (bsAt(regex.btMemEnd, i) ? stack[me].getMemPStr() : me) - str;
                     } else {
                         region.beg[i] = region.end[i] = Region.REGION_NOTPOS;
                     }
diff --git a/test/org/joni/test/TestU8.java b/test/org/joni/test/TestU8.java
index 539e3d1..8915175 100755
--- a/test/org/joni/test/TestU8.java
+++ b/test/org/joni/test/TestU8.java
@@ -326,5 +326,9 @@ public class TestU8 extends Test {
         ns("[^a\\x{80}]", "a", Option.CR_7_BIT);
 
         ns("(\\2)(\\1)", "");
+
+        x3s("\\(((?:[^(]|\\g<0>)*)\\)", "(abc)(abc)", 1, 4, 1);
+        x3s("\\(((?:[^(]|\\g<0>)*)\\)", "((abc)(abc))", 1, 11, 1);
+        x3s("\\(((?:[^(]|(\\g<0>))*)\\)", "((abc)(abc))", 6, 11, 2);
     }
 }

-- 
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