Skip to content

Commit 7823b93

Browse files
authored
restore compatibility with JRuby < 10.0 (#185)
due JRuby 10 API usage, the gem fails to load under older JRuby: jruby/jruby#9147 also a bunch of minor refactoring/cleanup in the Java extension. double checked building the ext under 10 test still pass using JRuby 9.4.
1 parent 747a3b5 commit 7823b93

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
include:
2929
- { os: windows-latest , ruby: mingw }
3030
- { os: windows-latest , ruby: mswin }
31+
- { os: ubuntu-latest , ruby: jruby-9.4 }
3132
exclude:
3233
- { os: macos-latest , ruby: 2.4 }
3334
- { os: macos-latest , ruby: 2.5 }

ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.jruby.anno.JRubyClass;
5050
import org.jruby.anno.JRubyMethod;
5151
import org.jruby.ast.util.ArgsUtil;
52-
import org.jruby.common.IRubyWarnings.ID;
5352
import org.jruby.exceptions.RaiseException;
5453
import org.jruby.runtime.ThreadContext;
5554
import org.jruby.runtime.builtin.IRubyObject;
@@ -83,24 +82,23 @@ public class RubyStringScanner extends RubyObject {
8382

8483
public static RubyClass createScannerClass(final Ruby runtime) {
8584
RubyClass Object = runtime.getObject();
86-
ThreadContext context = runtime.getCurrentContext();
8785

8886
RubyClass scannerClass = runtime.defineClass("StringScanner", Object, RubyStringScanner::new);
8987

9088
RubyClass standardError = runtime.getStandardError();
91-
RubyClass error = scannerClass.defineClassUnder(context, "Error", standardError, standardError.getAllocator());
92-
if (!Object.isConstantDefined(context, "ScanError")) {
93-
Object.defineConstant(context, "ScanError", error);
94-
Object.deprecateConstant(context, "ScanError");
89+
RubyClass error = scannerClass.defineClassUnder("Error", standardError, standardError.getAllocator());
90+
if (!Object.isConstantDefined("ScanError", true)) {
91+
Object.defineConstant("ScanError", error);
92+
Object.deprecateConstant(runtime, "ScanError");
9593
}
9694

9795
RubyString version = runtime.newString(STRSCAN_VERSION);
9896
version.setFrozen(true);
99-
scannerClass.setConstant(context, "Version", version);
97+
scannerClass.setConstant("Version", version);
10098
RubyString id = runtime.newString("$Id$");
10199
id.setFrozen(true);
102-
scannerClass.setConstant(context, "Id", id);
103-
scannerClass.deprecateConstant(context, "Id");
100+
scannerClass.setConstant("Id", id);
101+
scannerClass.deprecateConstant(runtime, "Id");
104102

105103
scannerClass.defineAnnotatedMethods(RubyStringScanner.class);
106104

@@ -186,7 +184,7 @@ public IRubyObject reset(ThreadContext context) {
186184
@JRubyMethod(name = "terminate")
187185
public IRubyObject terminate(ThreadContext context) {
188186
check(context);
189-
curr = str.getByteList().getRealSize();
187+
curr = str.size();
190188
clearMatchStatus();
191189
return this;
192190
}
@@ -224,7 +222,7 @@ public IRubyObject set_pos(ThreadContext context, IRubyObject pos) {
224222
Ruby runtime = context.runtime;
225223

226224
int i = RubyNumeric.num2int(pos);
227-
int size = str.getByteList().getRealSize();
225+
int size = str.size();
228226
if (i < 0) i += size;
229227
if (i < 0 || i > size) throw runtime.newRangeError("index out of range.");
230228
this.curr = i;
@@ -243,8 +241,7 @@ public IRubyObject charpos(ThreadContext context) {
243241
}
244242

245243
private IRubyObject extractRange(Ruby runtime, int beg, int end) {
246-
ByteList byteList = str.getByteList();
247-
int size = byteList.getRealSize();
244+
int size = str.size();
248245

249246
if (beg > size) return runtime.getNil();
250247
if (end > size) end = size;
@@ -255,7 +252,7 @@ private IRubyObject extractRange(Ruby runtime, int beg, int end) {
255252
private IRubyObject extractBegLen(Ruby runtime, int beg, int len) {
256253
assert len >= 0;
257254

258-
int size = str.getByteList().getRealSize();
255+
int size = str.size();
259256

260257
if (beg > size) return runtime.getNil();
261258
len = Math.min(len, size - beg);
@@ -297,7 +294,7 @@ private IRubyObject scan(ThreadContext context, IRubyObject regex, boolean succp
297294
regs = matchRegion;
298295
}
299296

300-
if (ret == -2) {
297+
if (ret == -2) {
301298
throw runtime.newRaiseException((RubyClass) getMetaClass().getConstant("ScanError"), "regexp buffer overflow");
302299
}
303300
if (ret < 0) return context.nil;
@@ -356,10 +353,6 @@ private void succ() {
356353
}
357354
}
358355

359-
private int currPtr() {
360-
return str.getByteList().getBegin() + curr;
361-
}
362-
363356
private int matchTarget() {
364357
if (fixedAnchor) {
365358
return str.getByteList().getBegin();
@@ -484,7 +477,7 @@ public IRubyObject getchCommon(ThreadContext context) {
484477
public IRubyObject get_byte(ThreadContext context) {
485478
check(context);
486479
clearMatchStatus();
487-
if (curr >= str.getByteList().getRealSize()) return context.nil;
480+
if (curr >= str.size()) return context.nil;
488481

489482
prev = curr;
490483
curr++;
@@ -761,8 +754,7 @@ public IRubyObject rest(ThreadContext context) {
761754
check(context);
762755
Ruby runtime = context.runtime;
763756

764-
ByteList value = str.getByteList();
765-
int realSize = value.getRealSize();
757+
int realSize = str.size();
766758

767759
if (curr >= realSize) {
768760
return RubyString.newEmptyString(runtime, str.getEncoding());

ext/jruby/org/jruby/ext/strscan/StringScannerLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.IOException;
44

55
import org.jruby.Ruby;
6-
import org.jruby.ext.strscan.RubyStringScanner;
76
import org.jruby.runtime.load.Library;
87

98
/**

0 commit comments

Comments
 (0)