Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 64e1b1d28586
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 929656a3a38d
Choose a head ref
  • 6 commits
  • 14 files changed
  • 1 contributor

Commits on Nov 4, 2016

  1. Copy the full SHA
    4780562 View commit details
  2. Copy the full SHA
    8a96013 View commit details
  3. Copy the full SHA
    fa678ef View commit details
  4. Copy the full SHA
    e26f60c View commit details
  5. Copy the full SHA
    6b97d20 View commit details
  6. Copy the full SHA
    929656a View commit details
4 changes: 0 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -260,10 +260,6 @@ public JRubyInterop getJRubyInterop() {
return jrubyInterop;
}

public Ruby getJRubyRuntime() {
return jrubyRuntime;
}

public CoreLibrary getCoreLibrary() {
return coreLibrary;
}
Original file line number Diff line number Diff line change
@@ -53,36 +53,26 @@
import org.jruby.RubyFixnum;
import org.jruby.RubyHash;
import org.jruby.RubyMatchData;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.RubySymbol;
import org.jruby.RubyThread;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.exceptions.RaiseException;
import org.jruby.parser.ReOptions;
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.encoding.EncodingCapable;
import org.jruby.runtime.encoding.MarshalEncoding;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.truffle.RubyContext;
import org.jruby.util.ByteList;
import org.jruby.util.KCode;
import org.jruby.util.Pack;
import org.jruby.util.RegexpSupport;
import org.jruby.util.Sprintf;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;
import org.jruby.util.cli.Options;
import org.jruby.util.collections.WeakValuedMap;
import org.jruby.util.io.EncodingUtils;

@@ -92,7 +82,6 @@
import static org.jruby.anno.FrameField.BACKREF;
import static org.jruby.anno.FrameField.LASTLINE;
import static org.jruby.util.StringSupport.CR_BROKEN;
import static org.jruby.util.StringSupport.CR_UNKNOWN;
import static org.jruby.util.StringSupport.EMPTY_STRING_ARRAY;
import static org.jruby.util.StringSupport.codeRangeScan;

@@ -1487,17 +1476,16 @@ private ClassicRegexp regexpInitializeString(RubyString str, RegexpOptions optio

// rb_reg_initialize
public ClassicRegexp regexpInitialize(ByteList bytes, Encoding enc, RegexpOptions options) {
Ruby runtime = getRuntime();
this.options = options;

//checkFrozen();
// FIXME: Something unsets this bit, but we aren't...be more permissive until we figure this out
//if (isLiteral()) throw runtime.newSecurityError("can't modify literal regexp");
if (pattern != null) throw runtime.newTypeError("already initialized regexp");
if (pattern != null) throw new org.jruby.truffle.language.control.RaiseException(context.getCoreExceptions().typeError("already initialized regexp", null));
if (enc.isDummy()) throw new UnsupportedOperationException(); // RegexpSupport.raiseRegexpError19(runtime, bytes, enc, options, "can't make regexp with dummy encoding");

Encoding[]fixedEnc = new Encoding[]{null};
ByteList unescaped = RegexpSupport.preprocess(runtime, bytes, enc, fixedEnc, RegexpSupport.ErrorMode.RAISE);
ByteList unescaped = preprocess(context, bytes, enc, fixedEnc, RegexpSupport.ErrorMode.RAISE);
if (fixedEnc[0] != null) {
if ((fixedEnc[0] != enc && options.isFixed()) ||
(fixedEnc[0] != ASCIIEncoding.INSTANCE && options.isEncodingNone())) {
@@ -1515,7 +1503,7 @@ public ClassicRegexp regexpInitialize(ByteList bytes, Encoding enc, RegexpOption
if (fixedEnc[0] != null) options.setFixed(true);
if (options.isEncodingNone()) setEncodingNone();

pattern = getRegexpFromCache(runtime, unescaped, enc, options);
pattern = getRegexpFromCache(context, unescaped, enc, options);
bytes.getClass();
str = bytes;
return this;
@@ -1928,7 +1916,6 @@ public static void appendOptions(ByteList to, RegexpOptions options) {
public ByteList toByteList() {
check();

Ruby runtime = getRuntime();
RegexpOptions newOptions = (RegexpOptions)options.clone();
int p = str.getBegin();
int len = str.getRealSize();
@@ -2003,7 +1990,7 @@ public ByteList toByteList() {
if (!newOptions.isExtended()) result.append((byte)'x');
}
result.append((byte)':');
RegexpSupport.appendRegexpString19(runtime, result, bytes, p, len, str.getEncoding(), null);
appendRegexpString19(result, bytes, p, len, str.getEncoding(), null);

result.append((byte)')');
result.setEncoding(getEncoding());
@@ -2012,6 +1999,80 @@ public ByteList toByteList() {
} while (true);
}

public void appendRegexpString19(ByteList to, byte[] bytes, int start, int len, Encoding enc, Encoding resEnc) {
int p = start;
int end = p + len;
boolean needEscape = false;
while (p < end) {
final int c;
final int cl;
if (enc.isAsciiCompatible()) {
cl = 1;
c = bytes[p] & 0xff;
} else {
cl = StringSupport.preciseLength(enc, bytes, p, end);
c = enc.mbcToCode(bytes, p, end);
}

if (!Encoding.isAscii(c)) {
p += StringSupport.length(enc, bytes, p, end);
} else if (c != '/' && enc.isPrint(c)) {
p += cl;
} else {
needEscape = true;
break;
}
}
if (!needEscape) {
to.append(bytes, start, len);
} else {
boolean isUnicode = StringSupport.isUnicode(enc);
p = start;
while (p < end) {
final int c;
final int cl;
if (enc.isAsciiCompatible()) {
cl = 1;
c = bytes[p] & 0xff;
} else {
cl = StringSupport.preciseLength(enc, bytes, p, end);
c = enc.mbcToCode(bytes, p, end);
}

if (c == '\\' && p + cl < end) {
int n = cl + StringSupport.length(enc, bytes, p + cl, end);
to.append(bytes, p, n);
p += n;
continue;
} else if (c == '/') {
to.append((byte) '\\');
to.append(bytes, p, cl);
} else if (!Encoding.isAscii(c)) {
int l = StringSupport.preciseLength(enc, bytes, p, end);
if (l <= 0) {
l = 1;
to.append(String.format("\\x%02X", c).getBytes(StandardCharsets.US_ASCII));
} else if (resEnc != null) {
int code = enc.mbcToCode(bytes, p, end);
to.append(String.format(StringSupport.escapedCharFormat(code, isUnicode), code).getBytes(StandardCharsets.US_ASCII));
} else {
to.append(bytes, p, l);
}
p += l;

continue;
} else if (enc.isPrint(c)) {
to.append(bytes, p, cl);
} else if (!enc.isSpace(c)) {
to.append(String.format("\\x%02X", c).getBytes(StandardCharsets.US_ASCII));
} else {
to.append(bytes, p, cl);
}
p += cl;
}
}
}

public String[] getNames() {
int nameLength = pattern.numberOfNames();
if (nameLength == 0) return EMPTY_STRING_ARRAY;
@@ -2341,7 +2402,7 @@ public static ClassicRegexp unmarshalFrom(UnmarshalStream input) throws java.io.
}*/

public Ruby getRuntime() {
return context.getJRubyRuntime();
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -195,4 +195,11 @@ public ByteList strConvEnc(ByteList byteList, Encoding encoding) {
public void setDefaultInternalEncoding(Encoding defaultInternalEncoding) {
jrubyRuntime.setDefaultInternalEncoding(defaultInternalEncoding);
}

public void setData(IRubyObject data) {
IRubyObject verbose = jrubyRuntime.getVerbose();
jrubyRuntime.setVerbose(jrubyRuntime.getNil());
jrubyRuntime.defineGlobalConstant("DATA", data);
jrubyRuntime.setVerbose(verbose);
}
}
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.joni.NameEntry;
import org.joni.Regex;
import org.joni.Syntax;
import org.jruby.common.IRubyWarnings;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.RubyContext;
187 changes: 187 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/parser/RubyWarnings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.truffle.parser;

import org.joni.WarnCallback;
import org.jruby.Ruby;
import org.jruby.common.IRubyWarnings;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.backtrace.RubyStackTraceElement;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.debug.DebugHelpers;

import java.util.EnumSet;
import java.util.Set;

/**
*
*/
public class RubyWarnings implements IRubyWarnings, WarnCallback {
private final RubyContext runtime;
private final Set<ID> oncelers = EnumSet.allOf(ID.class);

public RubyWarnings(RubyContext runtime) {
this.runtime = runtime;
}

@Override
public void warn(String message) {
warn(ID.MISCELLANEOUS, message);
}

@Override
public Ruby getRuntime() {
throw new UnsupportedOperationException();
}

@Override
public boolean isVerbose() {
return runtime.getJRubyInterop().isVerbose();
}

/**
* Prints a warning, unless $VERBOSE is nil.
*/
@Override
public void warn(ID id, ISourcePosition position, String message) {
if (!runtime.getJRubyInterop().warningsEnabled()) return;

warn(id, position.getFile(), position.getLine() + 1, message);
}

/**
* Prints a warning, unless $VERBOSE is nil.
*/
@Override
public void warn(ID id, String fileName, int lineNumber, String message) {
if (!runtime.getJRubyInterop().warningsEnabled()) return;

StringBuilder buffer = new StringBuilder(100);

buffer.append(fileName).append(':').append(lineNumber).append(": ");
buffer.append("warning: ").append(message).append('\n');
DebugHelpers.eval(runtime, "$stderr.write Truffle::Interop.from_java_string(message)", "message", buffer.toString());
}

/**
* Prints a warning, unless $VERBOSE is nil.
*/
@Override
public void warn(ID id, String fileName, String message) {
if (!runtime.getJRubyInterop().warningsEnabled()) return;

StringBuilder buffer = new StringBuilder(100);

buffer.append(fileName).append(' ');
buffer.append("warning: ").append(message).append('\n');
DebugHelpers.eval(runtime, "$stderr.write Truffle::Interop.from_java_string(message)", "message", buffer.toString());
}

@Override
public void warn(ID id, String message) {
if (!runtime.getJRubyInterop().warningsEnabled()) return;

RubyStackTraceElement[] stack = new RubyStackTraceElement[]{}; //getRubyStackTrace(runtime);
String file;
int line;

if (stack.length == 0) {
file = "(unknown)";
line = -1;
} else {
file = stack[0].getFileName();
line = stack[0].getLineNumber();
}

warn(id, file, line, message);
}

public void warnOnce(ID id, String message) {
if (!runtime.getJRubyInterop().warningsEnabled()) return;
if (oncelers.contains(id)) return;

oncelers.add(id);
warn(id, message);
}

/**
* Verbose mode warning methods, their contract is that consumer must explicitly check for runtime.isVerbose()
* before calling them
*/
public void warning(String message) {
if (!isVerbose()) return;
if (!runtime.getJRubyInterop().warningsEnabled()) return;

warning(ID.MISCELLANEOUS, message);
}

@Override
public void warning(ID id, String message) {
if (!runtime.getJRubyInterop().warningsEnabled() || !runtime.getJRubyInterop().isVerbose()) return;

RubyStackTraceElement[] stack = new RubyStackTraceElement[]{};//getRubyStackTrace(runtime);
String file;
int line;

if (stack.length == 0) {
file = "(unknown)";
line = -1;
} else {
file = stack[0].getFileName();
line = stack[0].getLineNumber();
}

warning(id, file, line, message);
}

/**
* Prints a warning, only in verbose mode.
*/
@Override
public void warning(ID id, ISourcePosition position, String message) {
warning(id, position.getFile(), position.getLine() + 1, message);
}

/**
* Prints a warning, only in verbose mode.
*/
@Override
public void warning(ID id, String fileName, int lineNumber, String message) {
if (!runtime.getJRubyInterop().warningsEnabled() || !runtime.getJRubyInterop().isVerbose()) return;

warn(id, fileName, lineNumber, message);
}

private static RubyStackTraceElement[] getRubyStackTrace(Ruby runtime) {
ThreadContext context = runtime.getCurrentContext();
RubyStackTraceElement[] stack = context.createWarningBacktrace(runtime);

return stack;
}
}
Loading